• C

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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
AnthemCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.