Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
#include<stdio.h>
#include<string.h>
#define ROWCAP 200
#define COLCAP   1000

int readRecords(char filename[], char records[][100], int* , int, int);
int main ()
{
      int i;
      char records[ROWCAP][COLCAP];
      int numOfRec;

      readRecords("input.txt",records,&numOfRec,ROWCAP,COLCAP);
      printf("%d",numOfRec);/* testing */

      for(i=0;i<numOfRec;i++)
      {
            printf("%s\n",records[i]);
      }

}
int readRecords(char filename[], char records[][100], int* numOfRecords, int rowCap, int colCap)
{
      FILE *inp;
      int flag = 0;
      int numberRow = 0;
      int status;
      int i=0;
      inp = fopen(filename,"r");

      status = fscanf(inp,"%s",records[numberRow]);
      printf("%s\n",records[numberRow]);/* testing */

            for( i = 1 ;status != EOF; i++ )
            {

                  status = fscanf(inp,"%s",records[i]);
                  printf("%s\n",records[i]);/* testing */
            }


      numberRow = i-1 ;
      *numOfRecords = numberRow;

      return flag;
}
Posted
Comments
José Amílcar Casimiro 27-Apr-13 9:14am    
What?

1 solution

You need to look at this in conjunction with your data: I would suggest that you use a debugger to single step through your code and examine variables to find out what is happening at each stage.

Presumably you are getting sensible values from your printf statements? But I would be wary of the code: you appear to be ignoring the sizes you set for the memory allocation *(using ROWCAP and COLCAP) when you fill your values into the records variable, so it is possible that you are corrupting other memory.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900