char main()/*Start of the function main???*/
{ 
	char choice1;
	char choices = 'y';
	while(choices == 'y' && choices != 'n'){/*while loop initialization*/
			print();
			getchar();
			scanf("%c",&choice1);
			printf("%c",choice1);
			switch(choice1){/*Switch case statement,,,*/
					case 'a':
					case 'A':
						addContact();
						break;
					case 'f':
					case 'F':
						search(contacts);
						break;
					case 'v':
					case 'V':
						list();
						break;
					case 'e':
					case 'E':
						edit(contacts);
						break;
					case 'd':
					case 'D':
						list();
						printf("Which contact do you to delete?\n");
						deleteCont(contacts);
					default: 
						printf("You pressed 1 EXIT status!!!!\n");
			}/*end of switch case...*/
	printf("\nIs there anything you want to add?Y/N");/*while loop update!!!*/
	getchar();
	scanf("%c",&choices);
	}
}/*end of function main()*/

my problem is the switch does not work properly...after the loop it jumps toward the default.....could anyone help on my problem....tnxx in advance....

char main() { /*Start of the function main???*/
    char choice1;
    char choices = 'y';
    while(choices == 'y' && choices != 'n') { /*while loop initialization*/
        print();
        getchar();
        scanf("%c",&choice1);
        printf("%c",choice1);
        switch(choice1) { /*Switch case statement,,,*/
        case 'a':
        case 'A':
            addContact();
            break;
        case 'f':
        case 'F':
            search(contacts);
            break;
        case 'v':
        case 'V':
            list();
            break;
        case 'e':
        case 'E':
            edit(contacts);
            break;
        case 'd':
        case 'D':
            list();
            printf("Which contact do you to delete?\n");
            deleteCont(contacts);
        default:
            printf("You pressed 1 EXIT status!!!!\n");
        }/*end of switch case...*/
        printf("\nIs there anything you want to add?Y/N");/*while loop update!!!*/
        getchar();
        scanf("%c",&choices);
    }
}/*end of function main()*/

sorry for wrong motions..i rewrited my post

> Last edited by syria718; 24 Minutes Ago at 09:15. Reason: i cant'n post perfectly sorry,,
It seems you still can't - you still haven't figured out [code]
[/code] tags.
How many hints do you need to do this?

getchar();
scanf("%c",&choice1);

When you type something for getchar and press enter, the linefeed '\n' goes into the choice1. That is scanf will not prompt the user to enter a character. Instead it will take the last key you pressed for getchar()

the problem is in this portion of the code

scanf("%c",&choice1);

try puting a space betewee " and %C when declaring the variable type char, this sometimes refuses to accept the input and porceeds to the end or enters a random input instead

try replacing that piece of code with this one and see what hapens

scanf(" %c",&choice1);

the problem is in this portion of the code

scanf("%c",&choice1);

try puting a space betewee " and %C when declaring the variable type char, this sometimes refuses to accept the input and porceeds to the end or enters a random input instead

try replacing that piece of code with this one and see what hapens

scanf(" %c",&choice1);

And how would that help? Why would the correct way (before your change) 'refuse' to accept input?

I took your code and tried making you a solution:

char main() { /*Start of the function main???*/
    
    
    char choice1;
    char choices = 'y';
    
    
    do{
        printf("Enter Command (n = no command): ");
        
        putchar((choice1=getchar()));
        
        //–––––––––––––––––––––––––
        switch(choice1) {
            case 'a':
            case 'A':
                addContact();
                break;
            case 'f':
            case 'F':
                search(contacts);
                break;
            case 'v':
            case 'V':
                list();
                break;
            case 'e':
            case 'E':
                edit(contacts);
                break;
            case 'd':
            case 'D':
                list();
                printf("Which contact do you to delete?\n");
                deleteCont(contacts);
            default:
                printf("You pressed 1 EXIT status!!!!\n");
        }
        //–––––––––––––––––––––––––
        
        
               
    }while(choice1!='n');
               
}/*end of function main()*/

Notice line 11 I set it up so the character entered in the input buffer captured by getchar is assigned to choice1 and putchar puts that character into the standard output. Also your code block appeared to have unneeded code (this is based on the snippet you posted; I imagine theres more) so I configured it to be more efficient. Tell me how it works and if you have any questions please don't hesitate.

commented: We don't want YOU to make a solition, we want you to help HIM find his own solution. Give him help, not a handout. -4

Since when is main() a char function? Of all the errors I've seen for main() , this is the first time for this one...

Of all the errors I've seen for main() , this is the first time for this one...

Sadly, not the first time for me. Usually the rationalization is that char is an integer type and the return values are all well within the range of char.

If you check syria's second post that includes his code it says "char main()" so I assumed it was correct

If you check syria's second post that includes his code it says "char main()" so I assumed it was correct

Yeah, it's not really the best practice to assume any kind of correctness from the code of obvious novices. ;) But hey, you can use this as a heads up to research things such as the valid definition of main(). Win.

commented: win indeed +17
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.