fscanf

C language - Fscanf and sprint commands in unix environment

I am trying to read file with 30 rows and 5 columns with separator of "tab". Each time I get only part of the rows. In the windows environment it's working good. Any idea why in unix it is not working? while (fscanf(FFMapFile, "%s\t%s\t%s\t%s\t%s\t", fnfMap[i].COS_ID, fnfMap[i].FF_First_Act, fnfMap[i].FF_Next_Act, nfMap[i].Free_FF_allo...

Width as a variable when using fscanf [C++]

I am trying to read in a certain portion of a file and that amount of data is different per line but I know how how many bytes of info I want. Like this: 5bytes.byte1byte2byte3byte4byte5CKSum //where # of bytes varies for each line (and there is no period only there for readability) Actual data: 05AABBCCDDEE11 03AABBCC22 04AABB...

How can I get how many bytes sscanf_s read in its last operation?

I wrote up a quick memory reader class that emulates the same functions as fread and fscanf. Basically, I used memcpy and increased an internal pointer to read the data like fread, but I have a fscanf_s call. I used sscanf_s, except that doesn't tell me how many bytes it read out of the data. Is there a way to tell how many bytes ssc...

fscanf multiple lines [c++]

I am reading in a file with multiple lines of data like this: :100093000202C4C0E0E57FB40005D0E0020C03B463 :1000A3000105D0E0022803B40205D0E0027C03027C :1000B30002E3C0E0E57FB40005D0E0020C0BB4011D I am reading in values byte by byte and storing them in an array. fscanf_s(in_file,"%c", &sc); // start code fscanf_s(in_file,"%...

Reading file using fscanf() in C

I need to read and print data from a file. I wrote the program like below, #include<stdio.h> #include<conio.h> int main(void) { char item[9], status; FILE *fp; if( (fp = fopen("D:\\Sample\\database.txt", "r+")) == NULL) { printf("No such file\n"); exit(1); } if (fp == NULL) { printf("Error Reading File\n"); } while(...

How to do conditional parsing with fscanf?

Hi there, I have some lines I want to parse from a text file. Some lines start with x and continue with several y:z and others are composed completely of several y:zs, where x,y,z are numbers. I tried following code, but it does not work. The first line also reads in the y in y:z. ... if (fscanf(stream,"%d ",&x)) if else (fscanf(strea...

why does fprintf doesn't work after fscanf?

Hello, I want to open a file for both writing and reading, but after I read from it I can't write: f_prefs = fopen(prefs_path, "r+"); while (fscanf(f_prefs, "%[^\n]\n", line) == 1) { ... do some stuff ... fprintf(f_prefs, "test"); // doesn't work ... } Any ideas? ...

C: How to read only the first word from each line?

Hi, I've done many simple procedures, but I'm only trying to read the first word into a char word[30] , from each line of a text file. I've tried, but without success. Oh, I have to reuse that char each time I read it. (To put in an ordered list each time I read it). Can anyone help me and show me a way to read this way from a file, i...

C: fscanf - infinite loop when first character matches

I am attempting to parse a text (CSS) file using fscanf and pull out all statements that match this pattern: @import "some/file/somewhere.css"; To do this, I have the following loop set up: FILE *file = fopen(pathToSomeFile, "r"); char *buffer = (char *)malloc(sizeof(char) * 9000); while(!feof(file)) { // %*[^@] : Read and discar...

C fscanf problem

If I open a file and use fscanf to read a file like this: 2 41 1 50 1 46 .... How do I tell C to read the first number and store it as a variable, then the second as another variable, run a loop, then move on to the next set? ...

C: fscanf erases integer variables values?

I've got a C program that encounters errors when I enter a while loop. I initialize a variable (fragmentcount) and write into it using fscanf and assign it a value of 4 (this works) int fragmentCount; if ((fscanf(fp, "%i", &fragmentCount)) == 1) { ... } However, when I try to access it in a while loop below, fragmentCount = 0 wh...