syntax error in C

I have a syntax error in my program, but I can't seem to find it! Please help!
/* Sara Bissonnette */

# include <stdio.h>


# define SIZE 50
# define SENTINEL -999



void readit(int, int *);
void sort(int, int);
void printout(int, int);


int main(void)

      {

      int list[SIZE], count=0;

      readit(list[], &count);
      sort(list[], count);
      printout(list[], count);

      }


void readit(int list[], int *count)

      {
      int i=0, valid, number;

      printf("This program will read in up to %d intergers", SIZE);
      printf(" and form a chart from them\nin increasing order.");
      printf("\n\nPlease type %d when done.\n\n" SENTINEL);
      printf("Enter your numbers now.\n");

      valid=scanf("%d", &number);

      while((i<SIZE)&&(number!=SENTINEL))
            {
            
            while(valid!=1)
                  {
                  printf("That is not a valid entry.\n");
                  printf("Please reenter:");
                  valid=scanf("%d", &number);
                  }

            list[i]=number;
            i++;
            scanf("%d", &number);
            }
      
      if(number!=SENTINEL)
            printf("Too many numbers.\nOnly %d are used.", SIZE);

      *count=i;
      
      }



void sort(int list[], int count)

      {
      int i, start, temp;

      for(start=0; start<count; start++)

            if(list[i]<list[start])
                  {
                  temp=list[i];
                  list[i]=list[start];
                  list[start]=temp;
                  }
      }
void printout(int list[], int count)
      
      {
      int ctr, i;
      
      printf(list[1]);
      

      for(i=2; i<count; i++)
            {
            ctr=1;
            while(list[i]==list[i-1])
                  {
                  ctr++;
                  i++;
                  }
            if(ctr>1)
                  printf("    (%d entries)/n",ctr);
            else
                  printf("/n");
            printf("%d", list[i]);

            }
      }
            



                  
                  
            
            
            

SaraBizAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AnthemConnect With a Mentor Commented:
SaraBiz,

    Here are the syntax errors that are occuring:

In you function declarations you should have:

void readit(int*, int *);
void sort(int*, int);
void printout(int*, int);

Instead of:

void readit(int, int *);
void sort(int, int);
void printout(int, int);


In your function calls you should have:

readit(list, &count);
sort(list, count);
printout(list, count);

Instead of:

readit(list[], &count);
sort(list[], count);
printout(list[], count);

There is also an issue with:

printf(list[1]);

It should be:

printf("%d", list[1]);


You are also having some big time issues with your sort function.  The issue is not a syntax error however.  Let me know if you will need some help on this as well, or if you were only looking for syntax errors.  Also let me know if you need any changes above explained.

-Thanks :0)





0
 
jhanceCommented:
What is your compiler telling you?


I do, however, see the following problems:

int main(void)

should return an int but doesn't


printf("    (%d entries)/n",ctr);

 should be

printf("    (%d entries)\n",ctr);


printf("/n");  

should be

printf("\n");


0
 
ozoCommented:
cfe: Error: 10246843.c, line 22: Syntax Error
 readit(list[], &count);
 ------------^
cfe: Error: 10246843.c, line 23: Syntax Error
 sort(list[], count);
 ----------^
cfe: Error: 10246843.c, line 24: Syntax Error
 printout(list[], count);
 --------------^
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
SaraBizAuthor Commented:
Thanks! Just a little problem with the same program now...fixed most of it, but I've got a little problem withthe printout...if three repetitions of a number are made, it only records two.  How can I fix this?
0
 
AnthemCommented:
Can you put the code back out here so I can see what changes that you made again so I am not going back over what you already treked down?

-Thanks :0)
0
 
SaraBizAuthor Commented:
Tried to fix it...sure didn't work! The last function isn't working right, and the program crashes if the user enters an invalid entry.




/* Sara Bissonnette */

# include <stdio.h>


# define SIZE 50
# define SENTINEL -999



void readit(int *, int *);
void sort(int*, int);
void printout(int*, int);


int main(void)

      {

      int list[SIZE], count=0;

      readit(list, &count);
      sort(list, count);
      printout(list, count);

      }


void readit(int list[], int *count)

      {
      int i=0, valid, number;

      printf("This program will read in up to %d intergers", SIZE);
      printf(" and form a chart from them\nin increasing order.");
      printf("\n\nPlease type %d when done.\n\n", SENTINEL);
      printf("Enter your numbers now.\n");

      valid=scanf("%d", &number);

      while((i<SIZE)&&(number!=SENTINEL))
            {
            
            while(valid!=1)
                  {
                  fflush(valid);
                  printf("That is not a valid entry.\n");
                  printf("Please reenter:");
                  valid=scanf("%d", &number);
                  }

            list[i]=number;
            i++;
            scanf("%d", &number);
            }
      
      if(number!=SENTINEL)
            printf("Too many numbers.\nOnly %d are used.", SIZE);

      *count=i;
      
      }



void sort(int list[], int count)

      {
      int i, start, temp;

      for(start=0; start<count; start++)

            if(list[i]<list[start])
                  {
                  temp=list[i];
                  list[i]=list[start];
                  list[start]=temp;
                  }
      }
void printout(int list[], int count)
      
      {
      int ctr=1, i;
      
      printf("%d", list[1]);
      
      
      for(i=2; i<count; i++)
            {
            
            if(list[i]==list[i-1])
                  ctr++;
                  
            else
                  {      
                  if(ctr>1)
                        {
                        printf("   (%d entries)\n", ctr);
                        ctr=1;
                        }
                  else
                        printf(" %d \n", list[i]);
                  }
            }
      }

                        
0
 
AnthemCommented:
Here are the changes you must make:

void sort(int list[], int count)

{
int i, start, temp;

for(start=0; start<count; start++)
      for ( i =0; i < start; i++ )
      {
            if(list[start]<list[i])
            {
                  temp=list[start];
                  list[start]=list[i];
                  list[i]=temp;
            }
      }
}
void printout(int list[], int count)

{

 printf("<%d entries>\n", count);

 for(int i=0; i<count; i++)
      printf(" %d \n", list[i]);
 
}

Plus you need to get rid of the fflush line you have in readit.

-Thanks :0)
0
 
AnthemCommented:
Hope that helps you :0).  I have to run for the evening so if you need anymore help on this tonight you will probably need someone else to help you.  Otherwise, I can respond tomorrow.

-Thanks
0
 
SaraBizAuthor Commented:
I don't think I said what this program is supposed to do...I have to make a list of ascending numbers, and if an entry is repeated, I must write next to it (2 entries), etc.  For example...
 If these numbers are entered

4
4
4
3
3
1
2
 It must list...

1
2
3 (2 entries)
4 (3 entries)

Thanks for your help though!
0
 
AnthemCommented:
Just curious if you got it to work?  Let me know.  Hope you did! :0)
0
All Courses

From novice to tech pro — start learning today.