hi, im new (as you're going to painfully aware of in a minute) to programming and was wondering if anyone could help with this little problem:
i am trying to read a number of values which are separated by newlines, and then manipulate each number until a number =<0 is observed.
is there a way i can use something like fgets() to read the line, then once the manipulation is over, print the result and for the process to be repeated with the number from the next line down in the file?
guessing this would mean id use a "while (integer in question >0), do manipulation and repeat" kinda loop. errr... yeah. the problem is i cant convert my crazy words into a language.
here is what i have so far:
do
{
puts("enter filename");
scanf("%s",name);
FILE*ft;//designates the title ft to the file
ft = fopen(name,"r");//opens the file
if( NULL !=ft)//if the file isnt NULL, then:
{
char filetemps[600];
fgets (filetemps , 600 , ft);//reads the first line only.
puts (filetemps);//just to check it was reading it.
{
else//if the file is NULL prints error statement
{
printf("\nCannot open, please try again %s\n", name);
}//ends else
printf("done\n");
return 2;
}while(name[0]!='z');//ends do
a sample input would be:
294
576
575
-1
thanks for any help you might give me!