Right now I use:
char record[BUFLEN];
if(fgets(record, BUFLEN, fp) != NULL) {
/* some code */
...
|
I have a file pointer which I am using with fgets() to give me a complete line along with the new line in the buffer.
I want to replace 1 char and ... |
Basically i am having problems with my code - this is homework so would rather not post it in here for obvious reasons. If it becomes truely important for me to ... |
gcc 4.5.1 c89
I am using the following code to read in a line of text from a configuration file. The configuration file is small at the moment, will grow with new ... |
So, I'm trying to find a way to fgets() a specific line in a text file in C, to copy the contents of the line into a more permanent buffer:
Essentially, I ... |
I need to read in a comma separated file, and for this I was going to use fgets. I was reading about it at http://www.cplusplus.com/ref/ and I noticed that the document said: "Reads characters from stream and stores them in string until (num -1) characters have been read or a newline or EOF character is reached, whichever comes first." My question ... |
Trond Valen writes: [color=blue] > Hi! > > Anyone who knows what the reason might be? fgets is supposed to return > null when reading EOF. I have a test for this, so my while loop should > exit, but it doesn't ...[/color] You forgot to post any code illustrating the observed behavior, so it is very difficult to know ... |
|
|
|
|
I have a piece of code that processes a file to get certain values out of it. Basically the input file is formatted like this: x y d (over multiple lines) x and y are positive integers and d is N, E, S or W. In my code are a few bits relating to errors. If you think they're relevent, ask, ... |
There is no standard way to do that - if you know the size of your lines, it is POSSIBLE that you could use fseek() to get to the nth line. But the common way to get to the nth line is to simply read n lines using (for example) fgets. Edit: And before someone else points it out, yes, fseek() ... |
|
I'm on a Mac running Tiger. I use TextWrangler for basic editing of text files and scripts. I created a simple 2 line text file and saved it with TextWrangler's Text Files encodings set up for Windows (CRLF). My C program does a fgets(). In the Xcode debugger, I see that the first line has a \r\n as the line endings, ... |
|
hey there... i'm pretty new to c too, but i've had to do a similar thing when i was sending configuration strings to a gps... but anyway, check this out... works for me. Code: #include #include void main(void) { FILE *cfgfile; int maxline = 256; int i=0, j=0; char cfgstring[16][256]; cfgfile = fopen("strings.txt", "r"); if (cfgfile==NULL) printf("can't open file\n"); ... |
|
#include int main() { char c[78]; /* declare a char array */ char d[6]; char e[90]; FILE *file,*filep,*file2; /* declare a FILE pointer */ file = fopen("data.txt", "r"); file2 = fopen("data2.txt", "r"); filep = fopen("dataprint.txt","w+"); /* open a text file for reading */ while(fgets(c, 78, file)!=NULL && fgets (d,6,file2)!=NULL) { concat (e,d,c);//fist attempt fprintf(filep,"%s",e); //fprintf(filep,"%s %s",d,c); //second attempt } printf("\n\nClosing ... |
|