Write a program that search a string from multidimensional array of characters.
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int main( void){
char languages[5][20] = {"Java", "Python", "C++", "C programming", "SQL"};
int i,index=-1;
char targetLanguage[20];
printf("Enter the language to search: ");
gets(targetLanguage);
for(i=0;i<5;i++){
if(strcmp(targetLanguage,languages[i])==0){
index=i;
}
}
if(index!=-1){
printf("\nThe language exists in the array.\n\n");
}else{
printf("\nThe language does NOT exist in the array.\n\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment