Monday 16 March 2009

C+ Super Array !!!

#include
#include
#define myfruit "grapes"

void main()
{
char name [20];
char string [20] = "Hello";
char string2 [20] = "How are you";
char dummy[20];
char fruit [20];

printf("\nEnter name : ");
scanf ("%s",&name);

gets(dummy); // to read the enter key and store in the string dummy

printf("\nYour name is %s",name);

printf("\nEnter your name again : ");
gets(name);

printf("\nYour nane is %s\n",name);
strcat(string,name);

printf("\nNow in string is %s",string);

printf("\nThe number of characters in name is %d",strlen(name));

strcpy(string,string2);
printf("\nNow in string is %s",string);

printf("\nThe value return is %d",strcmp("Apple","Papaya"));

printf("\nThe value return is %d",strcmp("Papaya","Apple"));

printf("\nThe value return is %d",strcmp("Apple","Apple"));

printf("\nGuess my favourite fruit ?");

gets(fruit);

if (strcmp(fruit,myfruit)==0)
printf("\nWell done! You guess it right!\n");
else
printf("\nSorry! %s is not my favourite fruit\n",fruit);
}

No comments: