Hey MacRumors! 
I am still learning the program language C with the help of: The C Programming Language, 2nd Edition by Brian and Kernighan.
I like the book very much and I think it is great you have to do some small exercises, to be sure you understand what you just wrote and what does what.
But in one of the chapters, with the headline "1.5 Character Input and Output "1.5.1 File Copying" ", they are talking about getchar() and putchar(). I am still not sure, still after the chapter what it is about, so if someone could explain me or give a link, that would be awesome
that's the code we want to compile. The exercises are
I use Xcode to write and compile (that's the best I know) as I can't get
to work with Terminal...
But when I run and compile with xcode, my logs only says
as you can see, the exercise is about to get the value of c, either 0 or 1. But it doesn't print out?
How do you get Xcode to work? How do I know if it 0 or 1? How can I write a program to tell me to print out (1-7)?
I tried to do:
but that didn't work either..
Help please!
EDIT:
I also have another problem..
doesn't print anything in Consol?
Is it me doing something wrong or is my Xcode ****ing up? :/
I am still learning the program language C with the help of: The C Programming Language, 2nd Edition by Brian and Kernighan.
I like the book very much and I think it is great you have to do some small exercises, to be sure you understand what you just wrote and what does what.
But in one of the chapters, with the headline "1.5 Character Input and Output "1.5.1 File Copying" ", they are talking about getchar() and putchar(). I am still not sure, still after the chapter what it is about, so if someone could explain me or give a link, that would be awesome
Code:
#include <stdio.h>
/* copy input to output; 2nd version */
main() {
int c;
while ((c = getchar()) != EOF)
putchar(c);
}
that's the code we want to compile. The exercises are
Code:
Exercsise 1-6. Verify that the expression getchar() != EOF is 0 or 1.
Exercise 1-7. Write a program to print the value of EOF.
I use Xcode to write and compile (that's the best I know) as I can't get
Code:
gcc filename.c -o filename
But when I run and compile with xcode, my logs only says
Code:
Debugger Console
[Session started at 2010-02-06 22:52:42 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 70706]
Running…
as you can see, the exercise is about to get the value of c, either 0 or 1. But it doesn't print out?
How do you get Xcode to work? How do I know if it 0 or 1? How can I write a program to tell me to print out (1-7)?
I tried to do:
Code:
#include <stdio.h>
/* copy input to output; 2nd version */
main() {
int c;
while ((c = getchar()) != EOF)
putchar(c);
printf("c = %d", c);
}
Help please!
EDIT:
I also have another problem..
Code:
#include <stdio.h>
int main()
{
int c, nl;
nl = 0; while ((c = getchar()) != EOF)
if (c == '\n') ++nl;
printf("%d\n", nl);
return 0;
}
Code:
Exercise 1-8. Write a program to count blanks, tabs, and newlines.
Exercise 1-9. Write a program to copy its input to its output, replacing each string of one or
more blanks by a single blank.
Exercise 1-10. Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.