Problems with input to a struct.
Hello, im new to this board.
I am sorry if i am posting incorrectly.
I have been writing some code for part of my task im working on.
I realised later my way of reading in code, there was a simpler way. where i could use the fgets command rather than a few while loops. But i am still quite new to C and i hadn't really worked that out when i started programming.
I am going to attempt to change my code to suit later. But for now i cant work out why i have this error
proj1.c: In function `main':
proj1.c:60: error: syntax error before "info_t"
proj1.c:64: error: syntax error before "info_t"
I am reasonably new to structures and havent done enough work with them i guess.
Again, sorry if i have posted wrong.. Also, thanks in advance for any help i receive
P.S: My code isn't done yet for my task, but everything i have done should be complete to do what im trying to print out now. Which is just see if the current use of reading the index file and obtain all the letters to the left of a ";" on each new line and store them as a phrase.
Hello, im new to this board.
I am sorry if i am posting incorrectly.
I have been writing some code for part of my task im working on.
I realised later my way of reading in code, there was a simpler way. where i could use the fgets command rather than a few while loops. But i am still quite new to C and i hadn't really worked that out when i started programming.
I am going to attempt to change my code to suit later. But for now i cant work out why i have this error
proj1.c: In function `main':
proj1.c:60: error: syntax error before "info_t"
proj1.c:64: error: syntax error before "info_t"
I am reasonably new to structures and havent done enough work with them i guess.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#define MAXCHARS 50
/* My structure */
typedef struct {
char *phrase[MAXCHARS];
char *filename[MAXCHARS];
} info_t;
int
main(int argc, char **argv)
{
/* Opens file for reading */
FILE *fp;
fp = fopen("Index.txt", "r");
int i=0, j=0, position;
int strdivider;
int next_char=0;
char buffer[MAXCHARS];
char temp[MAXCHARS];
while((next_char = getc (fp)) != EOF) {
while(next_char != '\n')
{
next_char=buffer[position];
position++;
}
/* gets the length of characters before the ; */
strdivider = strcspn(buffer,";");
for(i=0; i<strdivider; i++)
{
temp[i]=buffer[i];
}
/* Error On Line Below */
strcpy(info_t.phrase[j], temp);
j++;
/* test to check that the string passes correctly */
/* Error On Line Below */
printf("%s\n", info_t.phrase[j]);
/* I need to get the second part of the word */
}
/* For later with reading in user input */
printf("Enter Phrase: ");
return 0;
}
Again, sorry if i have posted wrong.. Also, thanks in advance for any help i receive
P.S: My code isn't done yet for my task, but everything i have done should be complete to do what im trying to print out now. Which is just see if the current use of reading the index file and obtain all the letters to the left of a ";" on each new line and store them as a phrase.
Last edited: