Thread: Pointer Error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    23

    Pointer Error

    Good day, I am having a pointer error in my string compare. can somebody please correct me? the program is reading have a rough text file of

    abcde
    ebcad
    acdbe

    and several same letters of the different orders and check which one is equal to the first one. I got the comparison right and it produces

    ae
    bb
    cc
    da
    ed

    and

    aa
    bc
    cd
    db
    ee

    so the output should be
    bb
    cc

    and

    aa
    ee

    but it's give me an error.

    Code:
    int main(void)
    {
    
       FILE *fp;
       char *status, *status2;
       
       int times;
       int looptimes;
        
        struct
        {
    	char numberofItems[2];
    	char answersToQuestions[50];
        } answerKey[SIZEANS];
        
        struct
       {
    	char studentID[7];
            char answers[50];
       } answer[SIZE];
     
       int y, szAns[] = {0,3,51};
       int i, sz[] = {0,6,51};
       char buff[1024];
       char buff2[1024];
       char insert[1024];
       int x = 0;   
       int w = 1;
    
       fp = fopen("Exam.txt","r");
       status = fgets(buff, sizeof(buff), fp);
       status2 = fgets(buff2,sizeof(buff2),fp);
       
    
       for(times = 0; times<1;times++)
       {
    	strncpy(answerKey[times].numberofItems, strtok(buff," "), szAns[1]);
            strncpy(answerKey[times].answersToQuestions,strtok(NULL," "), szAns[2]);
    	printf("%s %s",answerKey[times].numberofItems,answerKey[times].answersToQuestions);
            
    	for(w = 0; w <= strlen(answerKey[times].answersToQuestions) - 2; w++)
    	{
    	   printf("%c\n",answerKey[times].answersToQuestions[w]);
    	} 
    
       }
    
       while(status2 != NULL)
       {
    	strncpy(answer[i].studentID, strtok(buff2," "),sz[1]);
    	strncpy(answer[i].answers, strtok(NULL," "),sz[2]);
            printf("%s",answer[i].answers);
            
    	for(x = 0; x<=strlen(answer[i].answers) - 1; x++)
    	{	
    		
    		if(strcmp(answer[i].answers[x], answerKey[0].answersToQuestions[x]) == 0)
    		{
    		printf("%c",answer[i].answers[x]);
    		printf("%c\n",answerKey[0].answersToQuestions[x]);
    		}
    		
    	} 
    	x = 0;
    	i++;
    	status2 = fgets(buff2,sizeof(buff2),fp);
       }  
    
    printf("\n");
    fclose(fp);
    return 0;
    }
    Last edited by xaykogeki; 04-16-2010 at 01:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking to shlwapi.lib in C, MSVC CMD.
    By Joerge in forum Windows Programming
    Replies: 4
    Last Post: 08-07-2009, 05:18 PM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM