c - What operand to use for char type array? -


i've got silly problem , can hang of it. have easy c code (just want find if string str1 starts str2):

int main() {     int i, j;      char sir1[150], sir2[150], sir3[150];     printf("insert first string (sir1) , hit enter \n");     gets(sir1);     printf("insert second string (sir1) , hit enter \n");     gets(sir2);     printf("\n");     int len_sir2=strlen(sir2);     (i=0;i<len_sir2;i++)     {         sir3[i]=sir1[i];     }      (j=0;j<len_sir2;j++)     {         if (sir3[i]!=sir2[i]){printf("string 1 not start string 2\n");break;return 0;}     }     printf("sir1 starts sir2 \n");     getch();     } 

my problem example "bananna" , "ana", code seems have equal values sir2[0] , sir3[0], though in quick watch values showed 98'b' , 97'a'. i'm doing wrong? many in advance,

one error loop on j, use i inside loop.

for (j=0;j<len_sir2;j++)     {         if (sir3[i]!=sir2[i]){printf("string 1 not start string 2\n");break;return 0;}     } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -