controlsi 21 Newbie Poster

well i found the problems at line 61 and 67, but now im getting errors at line 52 and 63

controlsi 21 Newbie Poster

Ive been working on this program for a little while now. and
i keep getting the error messages:
proj6b.c:61: error: syntax error before '{' token
proj6b.c:68: error: syntax error before '{' token

ive looked over the code and cant seem to find were the problem is. I am also a newbie,
any help would great because this beast is due at 8 am.

#include <stdio.h>
#include <string.h>

#define STR_SIZE 25
#define ARR_SIZE 10
#define MAX 25

typedef struct
{
  char month [MAX];
  int day;
  int year;
}DATE;

typedef struct 
{
  char firstname[MAX];
  char lastname[MAX];
  DATE birthday; 
  char social[12];
}INFO;


int fillArray(FILE *inf, char arr[]);
void printArray(char arr[], int numEls);
void accessfile (FILE *inf, INFO *record);

int main(int argc , char *argv[])
{
   int numEls;
   DATE bday;
//   SSN snum;
   FILE *inf;
   INFO first[STR_SIZE];
   INFO last[STR_SIZE];
   DATE month;
   DATE day;
   DATE year;
   
   

   char arr[ARR_SIZE]; 
   enum months {January = 1, February, March, April, May, June, July, 
		August, September, November, December};
   enum months DateMonth;
   inf = fopen(argv[1], "r");
   printf("its got this far\n");
   printf("%d%s%s\n", month, &first, &last);
   numEls = fillArray(inf, arr);
   printArray(arr, numEls);
   fclose(inf);

   return 0;
}


int fillArray(FILE *inf, char arr[]);
{
   int i;
   for(i = 0; i < STR_SIZE; i++)
       accessfile(arr[i]);
} 

void printArray(char arr[], int numEls);
{
	int i ;
	for (i = 0; i < numEls; i++)
		printf("Name: %s, %s\n", last,first );

}



void accessfile (FILE *inf, INFO *record)
{
 if ((inf = fopen("argv[1]", "r")) != NULL)
   {
	fscanf(inf, "%s, %s %s %s %d, …
controlsi 21 Newbie Poster

This code is suppose to read from an inputed file and then fill and array and sort the student records with in that file. Im having alot of trouble debugging myself and this program is due with in two days.
the input will look like
lastname, firstname grade ssn birthday date of first attendence
my main problem is mostly the coding from 46 to 78 i know i have mistakes but im a pretty new to c programming.
thanks
david

#include <stdio.h>
#include <string.h> 
 
#define STR_SIZE 25   
#define ARR_SIZE 10   
#define MAX 25  
  
typedef struct  // structure that will be used in the program    
{
  char month [MAX];
  int day;
  int year;
}DATE;

typedef struct
{
  char social[9];
}SSN;
   
typedef struct
{
  int grade;
}GRADE;
   
typedef struct
{
  char firstname[MAX];
  char lastname[MAX];
  DATE birthday;
  SSN social[9];
  GRADE stugrade;
}INFO;
   

int fillArray(FILE *inf, arr[STR_SIZE]); // to fill the array from a the file 
void printArray(arr[], int numEls);// error messages are showing that  there is problem before 'arr'
   
   
int main(int argc, char *argv[])
{
   int numEls;
 
   arr[][STR_SIZE]; //is this legal for me to use?

   FILE *inf;
   enum months {January = 1, February, March, April, May, June, July,
                August, September, November, December};
   enum months DateMonth;
   SSN snum;  
   inf = fopen(argv[1], "r");
   numEls = fillArray(inf, arr);
   printArray(arr, numEls);
   fclose(inf); 
  
   return 0;
}
   
int fillArray(FILE *inf, arr[]); 
{
   int i;
   
   for (i = 0; i < STR_SIZE; i++)
      scanf("%s", arr[i]);
}
void printArray(arr[], int numEls);
{
        int i ; …
controlsi 21 Newbie Poster

thanks haha.
i was just reading the section in my book and its told me exactly what you said.
that the structure have to be initialized in a certain order

controlsi 21 Newbie Poster

Hello,
well this portion of code is basically just the structures from the program. everytime i compile the program i get an error at the INFOstructure.
i am using these structure in a program that read from a file and prints the data to the screen. my problem is that for some reason my structures are wrong.
thanks in advance for helping,
David

#include <stdio.h>
#include <string.h>
 
#define STR_SIZE 25
#define ARR_SIZE 10
#define MAX 15

typedef struct
{
  char month [MAX];
  int day;
  int year;
}DATE;

typedef struct  //this is the structure that is giving me problems.  for some reason the 
{                   // its  keeps saying no semicolon or union after struct.
  char firstname[MAX];
  char lastname[MAX];   
  DATE birthday;
  SSN social[9];
  GRADE stugrade;
}INFO;  
   
typedef struct
{
  char social;
}SSN;
   
typedef struct
{
  int grade;
}GRADE;
Ancient Dragon commented: Thanks for using code tags correctly +21
controlsi 21 Newbie Poster

sorry about that and thank you for formatting my code. I will make sure to do that from now on and i took your advice and read the post mentioned above.

Well, my problem is that the code above is suppose to read strings from a file and then take those strings and place them into a 2d array.

The problem that i am having is reading the actual strings from the text file and placing them into the array. It only seems to be printing the first letter in the file then nothing else.

input:
infile(which is the txt file i am using) contains:
lastname, firstname (about 5 names)
and the names are not sorted

output:
the names are printed here exactly as they are shown in the text file "infile"
ex.
lastname, firstname
doe, john
francis, chris

any help would be very appreciated

controlsi 21 Newbie Poster
#include <stdio.h>
#include <stdlib.h>

#define SIZE 5
#define MAX 10

void fillArray(char arr[][MAX]);
void printArray(char arr[][MAX]);
int fileOpen(void);

int main(void)
{
   char arr[SIZE][MAX];
   int success;
   fileOpen();
   if (success == 1)
   {
      fillArray(arr);
      printArray(arr);
   }
   else
        printf("File access failed");
   return 0;
}
int fileOpen(void)  //  ** this were i am having the most trouble
{
   char fileInput;
   char word[SIZE][MAX];
   FILE *input;
   int success;
   if ((input = fopen("infile", "r")) !=NULL)
   {
   
        while ((fileInput = fgetc(input)) != EOF)
            {
                        printf("\n file opened!");//remove
    
                printf("\n Its working!\n ");//emove
                strcpy(input, word); 
   
                putchar(fileInput);
                fillArray(word);
            }
   
   
                printf("Failure in opening \"infile\" for writing.\n");
        fclose(input);
 }
   else
        {
           printf("\n Could not access \"infile\" for reading.\n\n");
           success = 0;
        }
   return success;
}

void fillArray(char word[][MAX])
{  
   char arr[SIZE][MAX];  // i also need guidance on how to fill the array with the 	
				info from a the file "infile"
   int i, j;
   int names;
   names = 0;
   printf("FIllARRAY TIME!");
   for (i = 0; i < SIZE; i++)
        fscanf("%s", word[i]);
   for(j = 0; j < MAX; j++)
         if ( i < SIZE)
            if ( j < MAX)
           {
            printf("%s", i, word[i][MAX]);
            names = i;
            printf("Named pairs = %d", names);
            printf("\n\n");
           }
         else
          printf("problem with data presented!");
   
}
   
   
void printArray(char arr[][MAX])
{
   int i, j;
         
   for (i = 0; i < SIZE; i++)
   {
      for (j = 0; j < MAX; j++)
         printf("%s", arr[i][j]);
      printf("\n");
   }
            
}

any in sight would be helpful. im really under the gun and have been trying to get this to work for a couple of days.