0
char *ch;   
ch = fgets(buffer, 100, file);
printf("%s1\n", ch);   
printf("A(x) = ");  
while (!feof(file)) { 
    if (fscanf(file, "(%d,%d)", &a[i].coef, &a[i].exp) != 2) {

I have this code and I'm trying to write poly A. but when I run this, I get second row of input for A. There is no problem when I print ch, but there is problem when I'm trying to print A. The input is:

(5,2)(4,6)(5,7)(7,3)(1,0)(9,1)(5,5)
(5,1)(8,0)(8,6)(3,5)(1,3)(7,2)(9,7)(5,4)

I want the first row to be in A.

I tried to change fscanf(file) but I wasn't able to fix it.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Woo
  • 1
  • woo, can you correct your code? It seems to be incomplete. – ruud May 12 '23 at 10:55
  • Please ensure you have an [mcve], which people can test. That includes a simple test input file. – 9769953 May 12 '23 at 11:23
  • "but there is problem". So, what is the problem? You mention you have a problem, but you don't state what the exact problem is. Please state the precise problem, including errors, incorrect (and expected) output, warnings etc. – 9769953 May 12 '23 at 11:25
  • The problem *might* be that `buffer` isn't allocated correctly. But we can't see the declaration for that variable, so we can't tell. – Steve Summit May 12 '23 at 16:12
  • 1
    One problem is definitely your use of `feof`. See [Why is `while( !feof(file) )` always wrong?](https://stackoverflow.com/questions/5431941) – Steve Summit May 12 '23 at 16:13

0 Answers0