Problem with fscanf statement

This is a discussion on Problem with fscanf statement within the C Programming forums, part of the General Programming Boards category; Code: . . . printf("%d %lf %lf", a, b, c); input_status = fscanf(inp, "%d %lf %lf", &a, &b, &c); } ...

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    .
    .
    .
    printf("%d %lf %lf", a, b, c);
    input_status = fscanf(inp, "%d %lf %lf", &a, &b, &c);
    }
    	fclose(inp);
    for (j = 0; j <= 18; j++)
    	{
    	for(k = max_number((j-9), 0); k<= min_number(9, j); k++)
    		{
    		z[j] += x[k]*y[j-k];
    		}
    	printf("array z[%d] is %f", j, z[j]);
    	printf("\n");
    	}
    }
    You can't calculate z until you have read every single x and y out of the file.

  2. #32
    Registered User
    Join Date
    Nov 2008
    Posts
    27
    also when you do that. z[4] should be 25 or some integer. Why doesn't it give that?

  3. #33
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because you forgot to set all the elements of z to 0 before starting?

  4. #34
    Registered User
    Join Date
    Nov 2008
    Posts
    27
    I mean why for certain values of j do you get z[j] being some huge number?

  5. #35
    Registered User
    Join Date
    Nov 2008
    Posts
    27
    how do you do that?

  6. #36
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can initialize a variable when you declare it. So you could say
    Code:
    double z[19] = {0.0};
    which would give you an array of all zeroes.

  7. #37
    Registered User
    Join Date
    Nov 2008
    Posts
    27
    Thanks!

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with a switch statement.
    By Merholtz in forum C Programming
    Replies: 3
    Last Post: 10-19-2008, 04:21 PM
  2. Multithreading problem
    By Bacardi34 in forum C Programming
    Replies: 5
    Last Post: 09-02-2004, 02:26 PM
  3. Replies: 1
    Last Post: 08-31-2004, 04:07 AM
  4. problem using strtok and fscanf together
    By osal in forum C Programming
    Replies: 4
    Last Post: 07-20-2004, 02:21 PM
  5. If statement re-do problem
    By RoD in forum Windows Programming
    Replies: 5
    Last Post: 09-11-2002, 04:46 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21