By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

Comparing one string and one string from an array of strings in C

P: 1
//What i am doing wrong in the strcmp line!I still cant understand it and i am here for so many hours!Help

The compiler doesnt give me any errors or warnings

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SIZEX 45
  4.  
  5.  
  6. int main() {
  7.  
  8.     char *a[50][7];
  9.     a[0][4]="kosvid";
  10.     int flag=0;
  11.     int x;
  12.     char z[10];
  13.  
  14.     printf("Please enter the username \n");
  15.     scanf("%s",z);
  16.  
  17.     for(x=0;x<=SIZEX;x++)
  18.              {
  19.                 if(strcmp(a[x][4],z)==0)
  20.                 {
  21.                     flag=1;
  22.                 }
  23.             }
  24.  
  25.  
  26.     return 0;
  27. }
Dec 29 '15 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Expand|Select|Wrap|Line Numbers
  1.  a[0][4]="kosvid";
Read this: https://bytes.com/topic/c/insights/7...rrays-revealed

And then tell me what you think this code does.
Dec 30 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.