i use c language for my program(my practice). this code is work if i use 1 string in every variable. But, when i use array of string (2 dimension variable), str2[x] (the second string) isn't encoded, only str1[x] & str3[x] .
here my code (i get this code by browsing in here):
#include<stdio.h>
#include<conio.h>
char *encode(char *str){
int i=0;
while(str[i]!='\0'){
str[i]=str[i]-18;
i++;
}
return str;
}
int main(){
int i,n;
char str1[50][50],str2[50][50],str3[50][50];
printf("How many data: ");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("String 1: ");
scanf("%s",str1[i]);
printf("String 2: ");
scanf("%s",str2[i]);
printf("String 3: ");
scanf("%s",str3[i]);
}
for(i=0;i<n;i++){
printf("index-%d: %s - %s - %s\n",i,encode(str1[i]),encode(str2[i]),encode(str3[i]));
}
return 0;
}
for example, i input 2 data.
first input: "Test1", "Test2", "Test3"
Second input: "Test4", "Test5", "Test6"
output for index-0 for ex: index-0: BSab[ - - BSab!
(the second process is skiped) and no output for index-1 because the process is stop, i don't know why.
You're doing
fflush(stdin);
which is undefined behavior.