Code:
while (*my_string != EOF) {
Does this work? Because you are trying to dereference my_string which is uninitialized, which would (probably) mean a crash instantly. You need to allocate memory, copy in EOF and the you can check without problems.
Code:
my_string = (char *) malloc (nbytes + 1);
In C, you should never cast the return of malloc.
Code:
bytes_read = getline (&my_string, &nbytes, stream_f2);
I have never seen getline for C, but I'm pretty sure it takes a char* buffer instead of char**, which would would mean the first part is horribly wrong.
Code:
fprintf (stream_f1, my_string);
Never do this either. You have no idea what's stored inside my_string, so it can contain format specifiers which can cause all sorts of weirdness and cause crashes. To write a string, use fputs.
And aside from that, as they say, you never free the memory.
Originally Posted by
ckuttruff
Mike, thanks very much for your reply. The reason I'm starting with C is because a good friend of mine who programs in several languages recommended to me that I start with C, since it's a solid base language, and would help me adopt other languages and concepts more easily later on.
I don't know about that. I'd say you'll get better experience with C++. C is the lowest of lowest so to speak, and no other language that I know come close to C. C++ is a little higher level and will probably give you a little more to go on. Well, that's what I think anyway.
C++ is always to prefer over C. In embedded, you might need C++/C, though.
I'll check out the link you sent, and def. rework the call to malloc(). Yeah, I have to admit, I was not familiar with it, but I saw it as part of the call to getline.
It looks like you have programming studying to do. C isn't just a language you can mess around with without understanding it...