Hi,
I feel like I should know why this is happening...but I'm not sure why. I work on Sun UNIX machine. I am trying to simply write a file with a character array using
fprintf(). Like this...
FILE *fp;
char array[]="this is the output string";
open the file (tried text and binary)...
fprintf(fp, array);
fclose(fp);
...or I have tried other versions of that fprintf() statement...
fprintf(fp, "%s" , array);
etc...
When I use vi to open the file, it looks fine but I get a prompt saying incomplete last line. The only version of the fprintf() that doesn't produce that prompt is
fprint(fp, "%s\n", array);
Why do I need the newline? Why does that fix it? I'm guessing it flushes the line, but doesn't fclose(fp) do that already? I feel like theremust be another way. I even put a newline at the end of the array string and that didn't work, ie..
char array[]="this is the output string\n";
Any help would be appreciated.
Thanks.
-Tyler
I feel like I should know why this is happening...but I'm not sure why. I work on Sun UNIX machine. I am trying to simply write a file with a character array using
fprintf(). Like this...
FILE *fp;
char array[]="this is the output string";
open the file (tried text and binary)...
fprintf(fp, array);
fclose(fp);
...or I have tried other versions of that fprintf() statement...
fprintf(fp, "%s" , array);
etc...
When I use vi to open the file, it looks fine but I get a prompt saying incomplete last line. The only version of the fprintf() that doesn't produce that prompt is
fprint(fp, "%s\n", array);
Why do I need the newline? Why does that fix it? I'm guessing it flushes the line, but doesn't fclose(fp) do that already? I feel like theremust be another way. I even put a newline at the end of the array string and that didn't work, ie..
char array[]="this is the output string\n";
Any help would be appreciated.
Thanks.
-Tyler