Can someone please take a look and tell me where it all goes wrong

This is a discussion on Can someone please take a look and tell me where it all goes wrong within the C Programming forums, part of the General Programming Boards category; I'm trying to run this program and I'm getting about 70 errors starting at line 27 and I only have ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    42

    Can someone please take a look and tell me where it all goes wrong

    I'm trying to run this program and I'm getting about 70 errors starting at line 27 and I only have a little over 60 lines of code. I have run through it a few times and cannot see the fatal flaw. Visual studios has not flagged any of the syntax. I'm sure I omitted something important but cannot seem to identify it.

    Thanks,

    Mike

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    #define NUM_STU 5
    
    
        typedef struct
        {
            char name[26];
            int midterm[3];
            int final;
        }STUDENT;
    
    
    void insertionSort (STUDENT list[], int last);
    
    
    int main() 
    {
        STUDENT stuAry[NUM_STU] = 
        {
            {"Charles, George", {85, 94, 79}, 93},
            {"Adams, Karin",    {75, 91, 89}, 89},
            {"Nguyen, Tuan",   {87, 88, 89}, 90},
            {"Oh, Bill",       {76, 96, 88}, 91},    
            {"Chavez, Maria",  {83, 79, 94}, 91},
        };  //stuAry
    
    
        printf("Unsorted data:\n");
        for (STUDENT* pStuPtr = stuAry; pStuPtr <stuAry + NUM_STU; pStuPtr++) 
            printf("%-26s %4d %4d %4d %4d\n", pStuPtr->name, pStuPtr->midterm[0],pStuPtr->midterm[1],pStuPtr->midterm[2], pStuPtr->final);
        
        printf("\n");
    
    
        insertionSort(stuAry, NUM_STU - 1);
    
    
        printf("Sorted data:\n");
        for (STUDENT* pStuPtr = stuAry;    pStuPtr < stuAry + NUM_STU;    pStuPtr++) 
            printf("%-26s %4d %4d %4d %4d\n", pStuPtr->name, pStuPtr->midterm[0], pStuPtr->midterm[1], pStuPtr->midterm[2], pStuPtr->final);
        
        return 0;
    }
    
    
    void insertionSort(STUDENT list[], int last) 
    {
        bool    located;
        STUDENT temp;
        STUDENT* pCurrent;
        STUDENT* pWalker;
        STUDENT* pLast;
    
    
        for (pCurrent = list + 1, pLast = list + last; pCurrent <= pLast; pCurrent++)
        {
            located = false;
            temp    = *pCurrent;
    
    
            for (pWalker = pCurrent - 1; pWalker >= list && !located;) 
    
    
                if (strcmp(temp.name, pWalker->name)  < 0)
                {
                    *(pWalker + 1) = *pWalker;
                    pWalker--;
                }
                else 
                    located = true;
            
            *(pWalker + 1) = temp;
        }
        return;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > I'm trying to run this program and I'm getting about 70 errors starting at line 27
    ...
    > Visual studios has not flagged any of the syntax.
    Huh?
    How do you know there are 70 errors, when VS isn't showing any?

    Works OK here.
    It would work OK as a C program as well, if you fixed the bool / true / false thing.

    Code:
    $ gcc -x c++ foo.c
    $ ./a.out 
    Unsorted data:
    Charles, George              85   94   79   93
    Adams, Karin                 75   91   89   89
    Nguyen, Tuan                 87   88   89   90
    Oh, Bill                     76   96   88   91
    Chavez, Maria                83   79   94   91
    
    Sorted data:
    Adams, Karin                 75   91   89   89
    Charles, George              85   94   79   93
    Chavez, Maria                83   79   94   91
    Nguyen, Tuan                 87   88   89   90
    Oh, Bill                     76   96   88   91
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    Ok, since I cannot use <stdbool.h> in visual studios, I guess I will have to create a bool type. Does visual studios have any other includes that will work with bool?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    stdbool.h is a C99 header file, and VC++ isn't going to support C99 any time soon.

    So if you want it to remain a C program, you need to pick an approach that works in C89.
    Code:
    typedef enum { false, true } bool;   // for example
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    42
    Thanks Salem, My assigned book refers to C99 concepts even though we are working out of visual studios in class. I figured out that the majority of errors were because I was trying to initialize variables inside of the for loop. I guess that is accepted in C99.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-14-2011, 05:35 PM
  2. wrong wrong with my xor function?
    By Anddos in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2009, 01:38 PM
  3. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-27-2005, 11:48 PM
  4. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  5. what is wrong =(
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-01-2002, 05:58 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21