Closed Thread
Results 1 to 3 of 3

Thread: Help with C structures

  1. #1
    J-Camz is offline Newbie
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Help with C structures

    I just learned about c structures the other day but I can't seem to get them to work. It give the wrong result at the end.
    The errors I'm getting are:
    In function `main':
    24 [Warning] comparison between pointer and integer
    26 [Warning] assignment makes integer from pointer without a cast
    27 [Warning] passing arg 1 of `strcpy' from incompatible pointer type
    29 assignment makes integer from pointer without a cast

    Code:
    # include <stdio.h>
    # include <stdlib.h>
    # include <string.h>
    struct student
    {
           char name [50];
           char id [50];
           char score [50];
    };
    
    int main ()
    {
        int i;
        char sum=0, high=0,avg, highest[50][50];
        struct student stu[i];
        for (i=0; i<=4; i++)
        {
            printf ("Enter the student's name.");
            scanf ("%s", &stu[i].name);
            printf ("Enter the student's ID.");
            scanf ("%s", &stu[i].id);
            printf ("Enter the student's score.");
            scanf ("%f", &stu[i].score);
            if (stu[i].score>high)
            {
               high = stu[i].score;
               strcpy (highest,stu[i].name);
            }
            sum = sum + stu[i].score;
        }
        avg = sum/5;
        printf ("Student %s got the highest grade of %f", highest, high); 
        system ("pause");
        return 0;
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143

    Re: Help with C structures

    Line 24: you are attempting to compare a pointer to the first element of a char score[50] with a char high.

    The other errors (I didn't check all of them) appear to be related. Why isn't score, high, sum, and avg an int?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    J-Camz is offline Newbie
    Join Date
    Nov 2008
    Posts
    20
    Rep Power
    0

    Re: Help with C structures

    Thanks for replying but I figured out the problem

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C++ structures
    By Junaid92 in forum C and C++
    Replies: 5
    Last Post: 05-31-2011, 04:13 PM
  2. structures in C
    By huhz in forum C and C++
    Replies: 3
    Last Post: 11-28-2010, 09:15 AM
  3. Structures
    By josh in forum C Tutorials
    Replies: 1
    Last Post: 07-20-2010, 02:22 PM
  4. Using Structures
    By Guest in forum C Tutorials
    Replies: 7
    Last Post: 01-15-2010, 01:01 AM
  5. Structures
    By fread in forum C and C++
    Replies: 4
    Last Post: 10-11-2009, 05:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts