SaraBiz
asked on
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!=S ENTINEL))
{
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]);
}
}
/* 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!=S
{
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]);
}
}
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);
--------------^
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);
--------------^
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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)
-Thanks :0)
ASKER
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!=S ENTINEL))
{
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]);
}
}
}
/* 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!=S
{
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]);
}
}
}
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)
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)
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
-Thanks
ASKER
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!
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!
Just curious if you got it to work? Let me know. Hope you did! :0)
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");