473,748 Members | 7,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help in this programm in C

Hi.I am started learning Programm language C before some time.I am
trying to make a programm about a very simple "sell shop".This programm
hasn't got any compile problem but when i run it i face some other
ploblems which i can not correct.I would appreciated if someone take a
look at my programm so as to help me.I tried many times to find out
where my mistakes are but i didn't manage something.
I have made some comments due to the programm so as to make it more
easy to as.
Any recommendations about my writing style in the programm are
acceptable.
Please help me!!!

Programm
#include<stdio. h>
#include<stdlib .h>
#include<string .h>

/* Functions*/
int menu(void);
struct sells *insert(void);
struct sells *search(void);
int show(struct sells *list);
int exit(void);

/*Struct*/
struct sells{
char *tittle;
char *singer;
int price;
int count;
struct sells *next;
};

struct sells *list;
struct sells *alloc(void)
{
return(struct sells*)malloc(s izeof(struct sells));
}
/*Function main*/
int main(void)
{
menu();
return 0;
}

/*Function menu.In this function the user has the opportunity to choose

what he/she want to do*/
int menu(void)
{
int i;

printf("---------MENU---------\n");
printf("Press \"1\" to insert data\n");
printf("Press \"2\" to search data\n");
printf("Press \"3\" to show data\n");
printf("Press \"4\" to exit from programm\n");
putchar('\n\n') ;

printf("Make your choice\t");
scanf("%d",&i);

while((i<1)&&(i >4))
{
printf("You made wrong choice.\nPlease make a new
choice\n");
scanf("%d",&i);
}

switch(i)
{
case 1:
{
insert();
break;
}
case 2:
{
search();
break;
}
case 3:
{
show(list);
break;
}
case 4:
{
exit();
break;
}
}
return i;
}

/*In this function the user insert the data.*/
struct sells *insert(void)
{
char titlos[15];
char tragoudisths[15];
int timi;
struct sells *n;
float m_out;
int i;
m_out=0;
printf("%f\n",& m_out);
n=alloc();

printf("Give the title of the CD\n");
scanf("%s",&tit los);
getchar();
printf("Give the name of the singer\n");
scanf("%s",&tra goudisths);
getchar();

printf("Give the price of the CD\n");
scanf("%d",&tim i);
getchar();

while((timi<0)| |(timi>100))
{
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&tim i);
getchar();
}
getchar();

n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
n->price=timi;

if(list==NULL)
{
list=alloc();
list->tittle=strdup( n->tittle);
list->singer=strdup( n->singer);
list->price=n->price;
list->next=NULL;
printf("%f",&m_ out);
}
else if((m_out=(strc mp(titlos,n->tittle)))==0 )
{
list->count++;
printf("%f",&m_ out);
}
else if((m_out=(strc mp(titlos,n->tittle)))<0)
{
n=alloc();
n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
n->price=timi;
n->count=1;
n->next=list;
list=n;

printf("%s\t\t% s\t\t%d\t\t\n", list->tittle,list->singer,list->price);
}
else
{
list->next=insert( );
return list;
}
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return n;
}
/*In this function the user search for an element.Also he can modify
it.
If someone can i would like to tell me what i have to do so as to
delete an element.*/
struct sells *search(void)
{
char titlos[15];
int i,k,out;
char choice;

printf("Give the tittle of the CD that you want to find\n");
gets(titlos);
getchar();
if(list==NULL|| (out=strcmp(lis t->tittle,titlos) )>0)
{
printf("The tittle that you want doesn't exist.\n");
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return list;
}
else if(out==0)
{
printf("Tittle: \t%s\n",list->tittle);
printf("Singer: \t%s\n",list->singer);
printf("Price: \t%d\n",list->price);

printf("Do you want to make any change;\n");
printf("If Yes press \"1\" else \"0\" to return to
menu\n");
printf("Make your choice");
scanf("%d",&k);
switch(k)
{
case 1:
{
printf("Do you want ot change the tittle;\nPress Y(YES)
or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new tittle:\n");
gets(list->tittle);
getchar();
}
printf("Do you want ot change the name of the
singer;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new name:\n");
gets(list->singer);
getchar();
}
printf("Do you want ot change the price of the
CD;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new price:\n");
scanf("%d",&lis t->price);
while((list->price<0)&&(lis t->price>100))
{
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&lis t->price);
}
putchar('\n');
}
break;
}
case 0:
{
menu();
break;
}
}
}
return list;
}
/*Function which shows to the user all the element that has already
insert.
In this functio there is a problem.When i insert more the 3 elements,
these elements doesn't appear to me.I think that the problem is in my
insert
but i am not quite sure.*/
int show(struct sells *list)
{
int i,k;
k=1;
printf("\t\t-------LIST--------\n");
printf("Num\t\t Tittle\t\tSinge r\t\tPrice\n");
while(list!=NUL L)
{

printf("%d\t%s\ t\t%s\t\t%d\t\t \n",k,list->tittle,list->singer,list->price);

k++;
list=list->next;
}
printf("What do you want to do\n");
printf("Press \"1\" to retutn to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return 0;
}

/*Exit from the programm*/
int exit(void)
{
int i;

printf("Do you really want to exit from the programm;\n");
printf("If Yes press \"1\" else \"0\"\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
break;
}
return 0;
}
}

Jul 7 '06 #1
83 7848
de*****@hotmail .com said:
Hi.I am started learning Programm language C before some time.I am
trying to make a programm about a very simple "sell shop".This programm
hasn't got any compile problem
I beg to differ. See below. Fix this lot, starting with the first, and then
get back to us.

(Caution: in the following diagnostic report, line numbers may differ
slightly to those in your source.)

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c:10: conflicting types for `exit'
/usr/include/stdlib.h:577: previous declaration of `exit'
foo.c:26: warning: no previous prototype for `alloc'
foo.c: In function `menu':
foo.c:52: warning: multi-character character constant
foo.c:59: warning: unknown escape sequence `\ '
foo.c: In function `insert':
foo.c:102: warning: double format, pointer arg (arg 2)
foo.c:105: warning: char format, different type arg (arg 2)
foo.c:108: warning: char format, different type arg (arg 2)
foo.c:115: warning: unknown escape sequence `\ '
foo.c:116: warning: unknown conversion type character ` ' in format
foo.c:116: warning: too many arguments for format
foo.c:120: warning: implicit declaration of function `strdup'
foo.c:120: warning: assignment makes pointer from integer without a cast
foo.c:121: warning: assignment makes pointer from integer without a cast
foo.c:126: warning: assignment makes pointer from integer without a cast
foo.c:127: warning: assignment makes pointer from integer without a cast
foo.c:130: warning: double format, pointer arg (arg 2)
foo.c:135: warning: double format, pointer arg (arg 2)
foo.c:140: warning: assignment makes pointer from integer without a cast
foo.c:141: warning: assignment makes pointer from integer without a cast
foo.c: In function `search':
foo.c:214: warning: unknown escape sequence `\ '
foo.c:222: warning: unknown escape sequence `\ '
foo.c:223: warning: unknown conversion type character ` ' in format
foo.c:223: warning: too many arguments for format
foo.c:232: warning: unknown escape sequence `\ '
foo.c:242: warning: unknown escape sequence `\ '
foo.c:252: warning: unknown escape sequence `\ '
foo.c:253: warning: unknown conversion type character ` ' in format
foo.c:253: warning: too many arguments for format
foo.c: At top level:
foo.c:276: warning: declaration of `list' shadows global declaration
foo.c: In function `show':
foo.c:277: warning: declaration of `list' shadows global declaration
foo.c: In function `exit':
foo.c:335: warning: control reaches end of non-void function
make: *** [foo.o] Error 1

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #2
de*****@hotmail .com napsal(a):
Hi.I am started learning Programm language C before some time.I am
trying to make a programm about a very simple "sell shop".This programm
hasn't got any compile problem but when i run it i face some other
ploblems which i can not correct.I would appreciated if someone take a
look at my programm so as to help me.I tried many times to find out
where my mistakes are but i didn't manage something.
I have made some comments due to the programm so as to make it more
easy to as.
Any recommendations about my writing style in the programm are
acceptable.
Coding style? yes, try to use indent in way such this one:
indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs
(un*x utility for indentation)
Please help me!!!

Programm
#include<stdio. h>
#include<stdlib .h>
#include<string .h>

/* Functions*/
int menu(void);
struct sells *insert(void);
struct sells *search(void);
int show(struct sells *list);
int exit(void);

/*Struct*/
struct sells{
char *tittle;
char *singer;
int price;
int count;
struct sells *next;
};

struct sells *list;
struct sells *alloc(void)
{
return(struct sells*)malloc(s izeof(struct sells));
you don't need to cast.
}
/*Function main*/
int main(void)
{
menu();
return 0;
}

/*Function menu.In this function the user has the opportunity to choose

what he/she want to do*/
int menu(void)
{
int i;

printf("---------MENU---------\n");
printf("Press \"1\" to insert data\n");
printf("Press \"2\" to search data\n");
printf("Press \"3\" to show data\n");
printf("Press \"4\" to exit from programm\n");
You may use puts for these.
putchar('\n\n') ;

printf("Make your choice\t");
scanf("%d",&i);

while((i<1)&&(i >4))
{
printf("You made wrong choice.\nPlease make a new
choice\n");
scanf("%d",&i);
}

switch(i)
{
case 1:
{
insert();
break;
}
case 2:
{
search();
break;
}
case 3:
{
show(list);
break;
}
case 4:
{
exit();
break;
}
}
return i;
}

/*In this function the user insert the data.*/
struct sells *insert(void)
{
char titlos[15];
char tragoudisths[15];
int timi;
struct sells *n;
float m_out;
int i;
m_out=0;
you can do float m_out = 0;
printf("%f\n",& m_out);
n=alloc();
check for NULL.
>
printf("Give the title of the CD\n");
scanf("%s",&tit los);
This is bug-prone. If I enter char 15, it will crash.
Another thing, turn on warnings, it would tell you, it's bad.
titlos is pointer yet, so scanf("%s", titlos); is correct,
getchar();
printf("Give the name of the singer\n");
scanf("%s",&tra goudisths);
....
getchar();

printf("Give the price of the CD\n");
scanf("%d",&tim i);
getchar();

while((timi<0)| |(timi>100))
{
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&tim i);
getchar();
}
getchar();

n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
NULLs handling
n->price=timi;

if(list==NULL)
{
list=alloc();
again
list->tittle=strdup( n->tittle);
list->singer=strdup( n->singer);
list->price=n->price;
list->next=NULL;
printf("%f",&m_ out);
why pointer?
}
else if((m_out=(strc mp(titlos,n->tittle)))==0 )
{
list->count++;
printf("%f",&m_ out);
....
}
else if((m_out=(strc mp(titlos,n->tittle)))<0)
{
n=alloc();
....
n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
n->price=timi;
n->count=1;
n->next=list;
list=n;

printf("%s\t\t% s\t\t%d\t\t\n", list->tittle,list->singer,list->price);
}
else
{
list->next=insert( );
return list;
}
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return n;
}
/*In this function the user search for an element.Also he can modify
it.
If someone can i would like to tell me what i have to do so as to
delete an element.*/
struct sells *search(void)
{
char titlos[15];
int i,k,out;
char choice;

printf("Give the tittle of the CD that you want to find\n");
gets(titlos);
getchar();
if(list==NULL|| (out=strcmp(lis t->tittle,titlos) )>0)
{
printf("The tittle that you want doesn't exist.\n");
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return list;
}
else if(out==0)
{
printf("Tittle: \t%s\n",list->tittle);
printf("Singer: \t%s\n",list->singer);
printf("Price: \t%d\n",list->price);

printf("Do you want to make any change;\n");
printf("If Yes press \"1\" else \"0\" to return to
menu\n");
printf("Make your choice");
scanf("%d",&k);
switch(k)
{
case 1:
{
printf("Do you want ot change the tittle;\nPress Y(YES)
or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new tittle:\n");
gets(list->tittle);
getchar();
}
printf("Do you want ot change the name of the
singer;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new name:\n");
gets(list->singer);
getchar();
}
printf("Do you want ot change the price of the
CD;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new price:\n");
scanf("%d",&lis t->price);
while((list->price<0)&&(lis t->price>100))
{
unneeded { }
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&lis t->price);
}
putchar('\n');
}
break;
}
case 0:
{
menu();
break;
}
}
}
return list;
}
/*Function which shows to the user all the element that has already
insert.
In this functio there is a problem.When i insert more the 3 elements,
these elements doesn't appear to me.I think that the problem is in my
insert
but i am not quite sure.*/
int show(struct sells *list)
{
int i,k;
k=1;
printf("\t\t-------LIST--------\n");
printf("Num\t\t Tittle\t\tSinge r\t\tPrice\n");
while(list!=NUL L)
{

printf("%d\t%s\ t\t%s\t\t%d\t\t \n",k,list->tittle,list->singer,list->price);

k++;
list=list->next;
}
printf("What do you want to do\n");
printf("Press \"1\" to retutn to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return 0;
}

/*Exit from the programm*/
int exit(void)
{
int i;

printf("Do you really want to exit from the programm;\n");
printf("If Yes press \"1\" else \"0\"\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
break;
}
Why you call menu again, when you want to exit? Call exit(0);, but cleanup before.
return 0;
}
}

--
js
Jul 7 '06 #3
On Fri, 07 Jul 2006 08:38:54 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>de*****@hotmai l.com said:
>Hi.I am started learning Programm language C before some time.I am
trying to make a programm about a very simple "sell shop".This programm
hasn't got any compile problem

I beg to differ. See below. Fix this lot, starting with the first, and then
get back to us.

(Caution: in the following diagnostic report, line numbers may differ
slightly to those in your source.)

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
And then top it off with a run through PC-lint from
http://www.gimpel.com/ (warnings like 525 are supressed, and line
numbers may differ slightly to those in your source):

PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
1985-2006

--- Module: stdc.c (C)
_
int exit(void);
stdc.c(10) : Error 18: Symbol 'exit(int)' redeclared (void/nonvoid,
arg. count) conflicts with line 261, file stdlib.h
stdlib.h(261) : Info 830: Location cited in prior message
_
int exit(void);
stdc.c(10) : Warning 532: Return mode of function 'exit(int)'
inconsistent with line 261, file stdlib.h
stdlib.h(261) : Info 830: Location cited in prior message
_
menu();
stdc.c(33) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 6)
stdc.c(6) : Info 830: Location cited in prior message
_
#... = (char)(('\n\n') )) : _flsbuf((('\n\n ')),((&_iob[1])))) /*lint
-restore *
#... ('\n\n'),stdout )
putchar('\n\n') ;
stdc.c(51) : Info 742: Multiple character constant
_
#... _flsbuf((('\n\n ')),((&_iob[1])))) /*lint -restore */
#... ('\n\n'),stdout )
putchar('\n\n') ;
stdc.c(51) : Info 742: Multiple character constant
_
insert();
stdc.c(66) : Warning 534: Ignoring return value of function
'insert(void)' (compare with line 7)
stdc.c(7) : Info 830: Location cited in prior message
_
search();
stdc.c(71) : Warning 534: Ignoring return value of function
'search(void)' (compare with line 8)
stdc.c(8) : Info 830: Location cited in prior message
_
show(list);
stdc.c(76) : Warning 534: Ignoring return value of function
'show(struct sells *)' (compare with line 9)
stdc.c(9) : Info 830: Location cited in prior message
_
exit();
stdc.c(81) : Error 118: Too few arguments (0) for prototype
'exit(int)'
_
}
stdc.c(84) : Info 744: switch statement has no default
_
printf("%f\n",& m_out);
stdc.c(100) : Warning 559: Size of argument no. 2 inconsistent with
format
_
scanf("%s",&tit los);
stdc.c(104) : Warning 545: Suspicious use of &
stdc.c(104) : Warning 561: (arg. no. 2) indirect object inconsistent
with format
_
getchar();
stdc.c(105) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
scanf("%s",&tra goudisths);
stdc.c(109) : Warning 545: Suspicious use of &
stdc.c(109) : Warning 561: (arg. no. 2) indirect object inconsistent
with format
_
getchar();
stdc.c(110) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
getchar();
stdc.c(114) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
getchar();
stdc.c(120) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
getchar();
stdc.c(122) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
printf("%f",&m_ out);
stdc.c(135) : Warning 559: Size of argument no. 2 inconsistent with
format
_
printf("%f",&m_ out);
stdc.c(140) : Warning 559: Size of argument no. 2 inconsistent with
format
_
printf("Press \"1\" to return to menu or \"2\" to exit\n");
stdc.c(159) : Warning 539: Did not expect positive indentation from
line 154
stdc.c(154) : Info 830: Location cited in prior message
_
printf("Press \"1\" to return to menu or \"2\" to exit\n");
stdc.c(159) : Warning 539: Did not expect positive indentation from
line 142
stdc.c(142) : Info 830: Location cited in prior message
_
printf("Press \"1\" to return to menu or \"2\" to exit\n");
stdc.c(159) : Warning 539: Did not expect positive indentation from
line 137
stdc.c(137) : Info 830: Location cited in prior message
_
menu();
stdc.c(167) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 42)
stdc.c(42) : Info 830: Location cited in prior message
_
exit();
stdc.c(172) : Error 118: Too few arguments (0) for prototype
'exit(int)'
_
}
stdc.c(175) : Info 744: switch statement has no default
_
gets(titlos);
stdc.c(191) : Warning 534: Ignoring return value of function
'gets(char *)' (compare with line 324, file stdio.h)
stdio.h(324) : Info 830: Location cited in prior message
_
gets(titlos);
stdc.c(191) : Warning 421: Caution -- function 'gets(char *)' is
considered dangerous
_
getchar();
stdc.c(192) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
menu();
stdc.c(204) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 42)
stdc.c(42) : Info 830: Location cited in prior message
_
exit();
stdc.c(209) : Error 118: Too few arguments (0) for prototype
'exit(int)'
_
}
stdc.c(212) : Info 744: switch statement has no default
_
getchar();
stdc.c(231) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
gets(list->tittle);
stdc.c(235) : Warning 534: Ignoring return value of function
'gets(char *)' (compare with line 324, file stdio.h)
stdio.h(324) : Info 830: Location cited in prior message
_
gets(list->tittle);
stdc.c(235) : Warning 421: Caution -- function 'gets(char *)' is
considered dangerous
_
getchar();
stdc.c(236) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
getchar();
stdc.c(240) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
gets(list->singer);
stdc.c(244) : Warning 534: Ignoring return value of function
'gets(char *)' (compare with line 324, file stdio.h)
stdio.h(324) : Info 830: Location cited in prior message
_
gets(list->singer);
stdc.c(244) : Warning 421: Caution -- function 'gets(char *)' is
considered dangerous
_
getchar();
stdc.c(245) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
getchar();
stdc.c(249) : Warning 534: Ignoring return value of function
'_filbuf(struct _iobuf *)' (compare with line 275, file stdio.h)
stdio.h(275) : Info 830: Location cited in prior message
_
scanf("%d",&lis t->price);
stdc.c(257) : Info 725: Expected positive indentation from line 254
stdc.c(254) : Info 830: Location cited in prior message
_
menu();
stdc.c(265) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 42)
stdc.c(42) : Info 830: Location cited in prior message
_
}
stdc.c(268) : Info 744: switch statement has no default
_
{
stdc.c(281) : Warning 578: Declaration of symbol 'list' hides symbol
'list' (line 21)
stdc.c(21) : Info 830: Location cited in prior message
_
menu();
stdc.c(303) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 42)
stdc.c(42) : Info 830: Location cited in prior message
_
exit();
stdc.c(308) : Error 118: Too few arguments (0) for prototype
'exit(int)'
_
}
stdc.c(311) : Info 744: switch statement has no default
_
{
stdc.c(319) : Error 18: Symbol 'exit(int)' redeclared (void/nonvoid,
arg. count) conflicts with line 261, file stdlib.h
stdlib.h(261) : Info 830: Location cited in prior message
_
{
stdc.c(319) : Warning 515: Symbol 'exit(void)' has arg. count conflict
(0 vs. 1) with line 261, file stdlib.h
stdlib.h(261) : Info 830: Location cited in prior message
_
{
stdc.c(319) : Warning 532: Return mode of function 'exit(void)'
inconsistent with line 261, file stdlib.h
stdlib.h(261) : Info 830: Location cited in prior message
_
menu();
stdc.c(331) : Warning 534: Ignoring return value of function
'menu(void)' (compare with line 42)
stdc.c(42) : Info 830: Location cited in prior message
_
return 0;
stdc.c(338) : Warning 527: Unreachable code at token 'return'
_
}
stdc.c(339) : Info 744: switch statement has no default
_
}
stdc.c(340) : Warning 533: function 'exit(void)' should return a value
(see line 318)
stdc.c(318) : Info 830: Location cited in prior message

--- Global Wrap-up

Note 900: Successful completion, 91 messages produced
Tool returned code: 0

--
jay
Jul 7 '06 #4
jaysome said:

<snip>
And then top it off with a run through PC-lint from
http://www.gimpel.com/ (warnings like 525 are supressed, and line
numbers may differ slightly to those in your source):
Oooh, unkind. :-)

Some good news for the OP: my error list was somewhat inflated by my
cack-handed attempts at linewrap repair. Here is the revised list, which is
a fair bit shorter:

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c:10: conflicting types for `exit'
/usr/include/stdlib.h:577: previous declaration of `exit'
foo.c:26: warning: no previous prototype for `alloc'
foo.c: In function `menu':
foo.c:52: warning: multi-character character constant
foo.c: In function `insert':
foo.c:102: warning: double format, pointer arg (arg 2)
foo.c:105: warning: char format, different type arg (arg 2)
foo.c:108: warning: char format, different type arg (arg 2)
foo.c:120: warning: implicit declaration of function `strdup'
foo.c:120: warning: assignment makes pointer from integer without a cast
foo.c:121: warning: assignment makes pointer from integer without a cast
foo.c:126: warning: assignment makes pointer from integer without a cast
foo.c:127: warning: assignment makes pointer from integer without a cast
foo.c:130: warning: double format, pointer arg (arg 2)
foo.c:135: warning: double format, pointer arg (arg 2)
foo.c:140: warning: assignment makes pointer from integer without a cast
foo.c:141: warning: assignment makes pointer from integer without a cast
foo.c: At top level:
foo.c:276: warning: declaration of `list' shadows global declaration
foo.c: In function `show':
foo.c:277: warning: declaration of `list' shadows global declaration
foo.c: In function `exit':
foo.c:335: warning: control reaches end of non-void function
make: *** [foo.o] Error 1
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #5
On Fri, 07 Jul 2006 09:10:14 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>jaysome said:

<snip>
>And then top it off with a run through PC-lint from
http://www.gimpel.com/ (warnings like 525 are supressed, and line
numbers may differ slightly to those in your source):

Oooh, unkind. :-)
One of the warnings, 421, flagged gets() as being dangerous. The
PC-lint text documentation (MSG.TXT), which you can download from
Gimpel's web site, says this about warning 421:

421 Caution -- function 'Symbol' is considered dangerous -- This
message is issued (by default) for the built-in function gets.
This function is considered dangerous because there is no
mechanism to ensure that the buffer provided as first argument
will not overflow. A well known computer virus (technically a
worm) was created based on this defect. Through the -function
option, the user may designate other functions as dangerous.

What other Standard C functions would be good candidates for the
"-function" option?

Best regards
--
jay
Jul 7 '06 #6
jaysome said:
On Fri, 07 Jul 2006 09:10:14 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>>jaysome said:

<snip>
>>And then top it off with a run through PC-lint from
http://www.gimpel.com/ (warnings like 525 are supressed, and line
numbers may differ slightly to those in your source):

Oooh, unkind. :-)

One of the warnings, 421, flagged gets() as being dangerous. The
PC-lint text documentation (MSG.TXT), which you can download from
Gimpel's web site, says this about warning 421:
<snip>
>
What other Standard C functions would be good candidates for the
"-function" option?
Just gets(). But I'd flag a few others as being "experts-only" functions,
which you should not use in "real" code unless you know /exactly/ what
you're doing:

From <stdio.h>

freopen, fflush, setvbuf, setbuf, sprintf, vsprintf, fscanf,
scanf, sscanf, feof

From <string.h>

strncpy, strncat, strtok, memcpy, memset

From <stdlib.h>

atof, atoi, atol, calloc, malloc, realloc, free, atexit,
system

From <stdarg.h>

va_start, va_arg, va_end

From <setjmp.h>

setjmp, longjmp

From <signal.h>

signal

From <time.h>

clock
As a matter of fact, I was tempted to list every single function in the
standard library! But the ones I've listed do, I think, represent the
principal "gotcha" functions.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #7
jaysome <ja*****@spamco p.netwrote:
One of the warnings, 421, flagged gets() as being dangerous. The
PC-lint text documentation (MSG.TXT), which you can download from
Gimpel's web site, says this about warning 421:

421 Caution -- function 'Symbol' is considered dangerous -- This
message is issued (by default) for the built-in function gets.
This function is considered dangerous because there is no
mechanism to ensure that the buffer provided as first argument
will not overflow. A well known computer virus (technically a
worm) was created based on this defect. Through the -function
option, the user may designate other functions as dangerous.

What other Standard C functions would be good candidates for the
"-function" option?
None, really. gets() is the only one that can _not_ be used safely.
Functions like scanf() are easy to use unsafely, but can be made safe in
a simple, though WOMBATty, way, by constructing the format string at run
time, using something like (warning: not tested!)

sprintf(format_ string, "%%%ds", current_size_of _buffer);
scanf(format_st ring, destination_str ing);

Richard
Jul 7 '06 #8
Richard Bos said:

<snip>
Functions like scanf() are easy to use unsafely, but can be made safe in
a simple, though WOMBATty, way, by constructing the format string at run
time, using something like (warning: not tested!)

sprintf(format_ string, "%%%ds", current_size_of _buffer);
scanf(format_st ring, destination_str ing);
You'll want to add a check on the return value of scanf.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #9
<de*****@hotmai l.comwrote:

<just some random observations here and there>
Hi.I am started learning Programm language C before some time.I am
trying to make a programm about a very simple "sell shop".This programm
hasn't got any compile problem but when i run it i face some other
ploblems which i can not correct.I would appreciated if someone take a
look at my programm so as to help me.I tried many times to find out
where my mistakes are but i didn't manage something.
I have made some comments due to the programm so as to make it more
easy to as.
Any recommendations about my writing style in the programm are
acceptable.
Please help me!!!

Programm
#include<stdio. h>
#include<stdlib .h>
#include<string .h>

/* Functions*/
int menu(void);
struct sells *insert(void);
struct sells *search(void);
int show(struct sells *list);
int exit(void);
exit() is an existing fucntion in <stdlib.h It is not a good idea to reuse
names like this. Name your function exitx().
I wouldn't knowingly reuse names even if I *hadn't* included the particualar
include file.

/*Struct*/
struct sells{
char *tittle;
char *singer;
int price;
int count;
struct sells *next;
};

struct sells *list;
struct sells *alloc(void)
{
return(struct sells*)malloc(s izeof(struct sells));
}
/*Function main*/
int main(void)
{
menu();
return 0;
No data there. Your comments are detailed in nature, not "global". So I
can't tell what you are trying to do. I *guess* it is a linked list data
structure. But it is not owned by main, which would be typical. So I guess
it must be owned by menu. I'll look there.
}

/*Function menu.In this function the user has the opportunity to choose

what he/she want to do*/
int menu(void)
{
int i;

printf("---------MENU---------\n");
No, the only thing menu owns is a simple int. Who owns the list??? (If
there is a list.) Go to end.

printf("Press \"1\" to insert data\n");
printf("Press \"2\" to search data\n");
printf("Press \"3\" to show data\n");
printf("Press \"4\" to exit from programm\n");
putchar('\n\n') ;

printf("Make your choice\t");
scanf("%d",&i);

while((i<1)&&(i >4))
{
printf("You made wrong choice.\nPlease make a new
choice\n");
scanf("%d",&i);
}

switch(i)
{
case 1:
{
insert();
break;
}
case 2:
{
search();
break;
}
case 3:
{
show(list);
break;
}
case 4:
{
exit();
break;
}
}
return i;
}

/*In this function the user insert the data.*/
struct sells *insert(void)
{
char titlos[15];
char tragoudisths[15];
int timi;
struct sells *n;
float m_out;
int i;
m_out=0;
printf("%f\n",& m_out);
n=alloc();

printf("Give the title of the CD\n");
scanf("%s",&tit los);
getchar();
printf("Give the name of the singer\n");
scanf("%s",&tra goudisths);
getchar();

printf("Give the price of the CD\n");
scanf("%d",&tim i);
getchar();

while((timi<0)| |(timi>100))
{
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&tim i);
getchar();
}
getchar();

n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
n->price=timi;

if(list==NULL)
{
list=alloc();
list->tittle=strdup( n->tittle);
list->singer=strdup( n->singer);
list->price=n->price;
list->next=NULL;
printf("%f",&m_ out);
}
else if((m_out=(strc mp(titlos,n->tittle)))==0 )
{
list->count++;
printf("%f",&m_ out);
}
else if((m_out=(strc mp(titlos,n->tittle)))<0)
{
n=alloc();
n->tittle=strdup( titlos);
n->singer=strdup( tragoudisths);
n->price=timi;
n->count=1;
n->next=list;
list=n;

printf("%s\t\t% s\t\t%d\t\t\n", list->tittle,list->singer,list->price);
}
else
{
list->next=insert( );
return list;
}
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return n;
}
/*In this function the user search for an element.Also he can modify
it.
If someone can i would like to tell me what i have to do so as to
delete an element.*/
struct sells *search(void)
{
char titlos[15];
int i,k,out;
char choice;

printf("Give the tittle of the CD that you want to find\n");
gets(titlos);
getchar();
if(list==NULL|| (out=strcmp(lis t->tittle,titlos) )>0)
{
printf("The tittle that you want doesn't exist.\n");
printf("Press \"1\" to return to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return list;
}
else if(out==0)
{
printf("Tittle: \t%s\n",list->tittle);
printf("Singer: \t%s\n",list->singer);
printf("Price: \t%d\n",list->price);

printf("Do you want to make any change;\n");
printf("If Yes press \"1\" else \"0\" to return to
menu\n");
printf("Make your choice");
scanf("%d",&k);
switch(k)
{
case 1:
{
printf("Do you want ot change the tittle;\nPress Y(YES)
or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new tittle:\n");
gets(list->tittle);
getchar();
}
printf("Do you want ot change the name of the
singer;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new name:\n");
gets(list->singer);
getchar();
}
printf("Do you want ot change the price of the
CD;\nPress Y(YES) or N(NO)\t");
scanf("%s",&cho ice);
getchar();
if(choice=='Y')
{
printf("Give new price:\n");
scanf("%d",&lis t->price);
while((list->price<0)&&(lis t->price>100))
{
printf("You have insert a wrong price.\nGive a new
price.\n");
scanf("%d",&lis t->price);
}
putchar('\n');
}
break;
}
case 0:
{
menu();
break;
}
}
}
return list;
}
/*Function which shows to the user all the element that has already
insert.
In this functio there is a problem.When i insert more the 3 elements,
these elements doesn't appear to me.I think that the problem is in my
insert
but i am not quite sure.*/
int show(struct sells *list)
{
int i,k;
k=1;
printf("\t\t-------LIST--------\n");
printf("Num\t\t Tittle\t\tSinge r\t\tPrice\n");
while(list!=NUL L)
{

printf("%d\t%s\ t\t%s\t\t%d\t\t \n",k,list->tittle,list->singer,list->price);

k++;
list=list->next;
}
printf("What do you want to do\n");
printf("Press \"1\" to retutn to menu or \"2\" to exit\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
exit();
break;
}
}
return 0;
}

/*Exit from the programm*/
int exit(void)
{
int i;

printf("Do you really want to exit from the programm;\n");
Why do you assume the user is a moron? He just told you he wanted to exit.
printf("If Yes press \"1\" else \"0\"\n");
printf("Make your choice");
scanf("%d",&i);

switch(i)
{
case 1:
{
menu();
break;
}
case 2:
{
break;
}
return 0;
}
}
I would start over. Don't do the menu, do it last, after the fundamentals
are working. Start with sell and show and get them working. Don't do all
the fussy details. For example, you can add reasonableness checks later.
Do you really need five fields in your data structure to test your ideas? I
doubt it. Programs should grow, Start small, test, add, test, add, test,
......
Jul 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1846
by: Toni | last post by:
How can I insert a Backgroundimage in my C++ programm? Microsoft Visual Studio C++, Win 32 Konsolenanwendung. Can you answer me in germany, because my english is very bad. An example where very nice. I look for a german Newsserver about C++.
0
1038
by: Toni | last post by:
How can I insert a Backgroundimage in my C++ programm? Microsoft Visual Studio C++, Win 32 Konsolenanwendung. Can you answer me in germany, because my english is very bad. An example where very nice. I look for a german Newsserver about C++.
11
2925
by: gregsands | last post by:
Hi Im trying to install PHP 5.05 on Windows XP running Apache 2.0.54 Apache is running fine and ive made all the changes to the pnp.ini file and Apache config file, restarted Apache but all I get when trying to call my test.php file is a 404 error? http.config file: LoadModule php5_module "C:/php/php5apache2.dll" PHPIniDir "C:/php" AddType application/x-httpd-php .php
0
1867
by: Alexander F?hrmann | last post by:
Grüß euch! Wir haben hier in der Firma ein Problem mit Access! Sobald man im Access den VBA-Editor aufrufen will, kommt folgender fehler! -------------------- Runtime Error!
0
1090
by: sipetar | last post by:
I have two file. file looks like this: first file: A#b1#c1 B#b2#c2 B#b3 C#b4#c4 D#b5#c5
3
2956
by: Sven | last post by:
My current application is programmed in Visual Basic 6.0 It is a server and uses the winsock-control Now I have learned that the winsock control is not (fully) supported by VB.NET and that I have to use the "System.Net.Sockets namespace" As I am new to VB.NET, I want to ask if anyone knows a site where I can download a sample chat application programmed in VB. NET 2003? I mean there are a lot of Chat-programm-samples out there for VB...
2
1388
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder if there is a better and faster way to do it. To make it clear: The search&replace must be done within a programm not in the Framework or editor.
0
1223
by: shahrazad78 | last post by:
Hello every body , I need help in c/c++ in compiling I use linux , kosole editor to write a programm in c/c++ . And I have also gl/glu/glut libraries to use the function of opengl ,and I write a programm with C++ code and use also this function to disply the result with movie ,but now how can I write commend line in my editor to get exefile and then run this programm ,please I need quicke solution ...... I don't konow alot of commend line in...
3
2973
by: dreiko466 | last post by:
(sorry about my english...) I am a newbie in C (3 month expierience) I have wrote a simple test programm in VS2005, what i do wrong?Please... In this programm i create a double linked list.Then pass its first block pointer inside the structure Array to Array ->first and the last block pointer inside the structure Array to Array ->last.So i can manipulate the double linked list as a dynamic array. The cells of this dynamic array are...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.