Structures Error.

Joined
Aug 1, 2007
Messages
2
Reaction score
0
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.

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:
Joined
Aug 1, 2007
Messages
2
Reaction score
0
I have tried using varying functions on the j command, but i still have no luck, sorry to repost like this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top