code::blocks problem in entering a string?
code::blocks problem in entering a string?
include
#include
#include
void menu();
void view();
void add();
void display();
int choice;
int barcode[100],quantity[100];
char name[100][30];
float price[100];
int count = 0,option;
int main()
{
start:;
char repeat=’Y';
do{
menu();
switch(choice)
{
case 1:
system(“cls”);
view();
break;
case 2:
system(“cls”);
add();
break;
case 3:
system(“cls”);
display();
{
int input;
printf (“\nPlease any key to return to main menu :\n”);
scanf (“%s”,&input);
if( input == 1){
goto start;
}
}
break;
case 4:
system(“cls”);
{
char input;
printf (“\nDo you REALLY want to EXIT ?\n”);
printf (“\tIf YES enter y\n”);
printf (“\tIf NO enter n\n= “);
scanf (“%s”,&input);
if ( input ==’y'){
system(“cls”);
printf (“\n\t BYE BYE!!”);
printf (“\n\t Press any key to close\n”);
goto end;
}
else ( input ==’n');
system(“cls”);
goto start;
}
break;
}
continue;
}while(repeat==’Y’ || repeat==’y');
end:;
}
void menu()
{
system(“cls”);
printf(“\n\t+—————————————–+”);
printf(“\n\t:\t My Shop Inventory Record\t :\n”);
printf(“\t+—————————————–+\n\n\n”);
printf(“________________________________________________________\n\n\n”);
printf(“\t1.View Product Record\n”);
printf(“\t2.New Product Record\n”);
printf(“\t3.Display All Items\n”);
printf(“\t4.Exit\n\n\n”);
printf(“________________________________________________________\n\n\n”);
printf(“Your choice :”);
scanf(“%d”,&choice);
}
void view()
{
int codebar,view1,update,g,f,flag=0;
char choiceview,choiceupdate, tryagain;
view:
printf(“\n\n\tView Product Record\n”);
printf(“\t——————-\n”);
printf(“\tPlease enter the product’s barcode : “);
scanf(“%d”,&codebar);
printf(“\n\nPlease wait”);
Sleep(1000);
printf(“.”);
Sleep(1000);
printf(“.”);
Sleep(1000);
printf(“.”);
system(“cls”);
for(g=0;g<10;g++){
if(codebar == barcode[g]){
flag = 1;
break;}
}
if(flag == 1){
product: printf(“\n\nProduct Barcode = %d\n”,barcode[g]);
printf(“Product Name = %s\n”,name[g]);
printf(“Product Price = RM %.2f\n”,price[g]);
printf(“Product Quantity = %d\n”,quantity[g]);
printf(“\n\n1. Update\t 2. Delete\t 3. Main Menu\t”);
scanf(“%d”, &choiceview);
switch(choiceview){
case 1:
system(“cls”);
update: printf(“\nchoose to update\n”);
printf(“1. update product’s barcode\n”);
printf(“2. update product’s name\n”);
printf(“3. update product’s price\n”);
printf(“4. update product’s quantity\n:”);
scanf(“%d”,&choiceupdate);
switch(choiceupdate){
case 1:
system(“cls”);
printf(“\tPlease enter the new product’s barcode : “);
scanf(“%d”,&barcode[g]);
break;
case 2:
system(“cls”);
printf(“\tPlease enter the new product’s name : “);
scanf(“%s”,&name[g]);
break;
case 3:
system(“cls”);
printf(“\tPlease enter the new product’s price : RM “);
scanf(“%f”,&price[g]);
break;
case 4:
system(“cls”);
printf(“\tPlease enter the new product’s quantity :”);
scanf(“%d”,&quantity[g]);
break;
default:
system(“cls”);
printf(“\n\nTry again\n\n\n\n”);
goto update;
}
int input;
printf(“\n\nPlease wait”);
Sleep(1000);
printf(“.”);
Sleep(1000);
printf(“.”);
Sleep(1000);
printf(“.”);
system(“cls”);
printf (“\nYour update has been recorded. Press any key to return to main menu :\n”);
scanf (“%s”,&input);
if( input == 1){
}
break;
system(“cls”);
case 2:
barcode[g] = 0;
for(f=0;f<30;f++){
name[g][f]= ‘\
Tags: codeblocks, entering, problem, string
Under Forum

1 Comment for code::blocks problem in entering a string?
1. temp | November 13th, 2010 at 8:39 am
Please try to review your code……
You want to input string yet you used an int datatype (int input;……. then scanf(“%s”, &input) ?).
?@#$^@#$^$%$##$@#%$!!@#$????????????????????????????????????//
Anyway, try to use gets()
Try this:
char input[30];
// some codes/prompts in here
flushall(); gets(input);
And review your IT fundamentals.
And for other problems, its time for you to figure it out.
Leave a Comment for code::blocks problem in entering a string?
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed