Hi, New to C programming
I am trying to write a program in C in which i will be changing the value of a particular field based on the input of the user. I understand that there is no way in C language where one can just simply change a line (or a portion of it) in a file. Rather the entire file has to be copied into another file and somewhere in the process of copying you can change the field.(Please comment on this if you think i am wrong) what i am trying to do is to read from a file(which has some records and each record has 4 fields). the data in the file is somehow like this(Numbers represent Gold,Silver and Bronze:
USA: 47 72 33
Canada: 55 21 33
england: 55 40 71
the format remains the same throughout the file. my program has to change any of those three numbers for a particular name(which will be provided by the user).
users is asked to give 2 inputs: Name of the country, which is hold in "char country", and 'a letter and a number' for identifying which field needs to be changed and by how much.
following is the way i tried to code it but it wont work.
I get Tons of I's on the screen when i run this program in VS2008 , and
// to count the number of lines in the file
while(4==fscanf(fpt1,"%[^:]: %d %d %d\n", countrynew, &gold, &bronze, &silver))
// grap all the data into arrays.The problem is somewhat here as nothing is transfered to the arrays
fscanf(fpt1,"%[^:]: %d %d %d\n", countrya[i], golda[i], bronzea[i], silvera[i]);
// char country holds the name provided by the user and then i tried to check and see which record holds that country so that i change the required field.
if (input == 'g' || input == 'G')
else if (input =='s' || input =='S')
silvera[i] = newsilver;
else if (input == 'b' || input == 'B')
bronzea[i] == newbronze;
// now i tried to remove the file and create a new one and put the data hold in the arrays in that one.
for (i = 0 ; i <= count ; i++)
fprintf(fpt1,"%s: %d %d %d\n",countrya[i],golda[i],bronzea[i],silvera[i]);
: 0 0 0
: 0 0 0
when i run it using the linux cc compiler. Please help,