+ 2

Problem in Output

https://code.sololearn.com/c0kDHXg5Ggjw/?ref=app How would I know how many strings I entered(two-dimensional strings)? But definitely I entered less than what I allocated memory for!

12th May 2020, 8:16 PM
SAAMBRAM AKSHAY KUMAR REDDY
SAAMBRAM AKSHAY KUMAR REDDY - avatar
9 odpowiedzi
+ 1
char p[20][50] = {0}; <== do this. int i,j, len; for(i=0;i<20;i++) scanf("%s",p[i]); for(i=0; p[i][0]; i++) { len = strlen(p[i]); for(j=1; j < len; j++) printf("%c", p[i][j]); printf("%cay ", p[i][0]); }
12th May 2020, 10:06 PM
rodwynnejones
rodwynnejones - avatar
+ 6
SAAMBRAM AKSHAY KUMAR REDDY Change char p[10][10] to char p[20][50]
12th May 2020, 9:14 PM
A͢J
A͢J - avatar
+ 4
char p[10][13]; Is all that is needed to pass and stop your overflow issue.
12th May 2020, 9:49 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
What is your input and what error or what is the exact output you want?
12th May 2020, 8:22 PM
Abhay
Abhay - avatar
+ 2
Input: nevermind youve got them Expected Output: evermindnay ouveyay otgay hemtay Output by program: evermindnay ouveyay otgay hemtay (printing some unusual letters, symbols,etc) My program is also executing the string which I have not assigned! I need to overcome that!
12th May 2020, 8:29 PM
SAAMBRAM AKSHAY KUMAR REDDY
SAAMBRAM AKSHAY KUMAR REDDY - avatar
+ 2
for(i=0; p[i][0]; i++) { len=strlen(p[i]); for(j=1;j<len;j++) printf("%c",p[i][j]); printf("%cay ",p[i][0]); }
12th May 2020, 9:05 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Still the output is giving some unusual symbols at 4,8,9,10 no. of strings!
12th May 2020, 9:14 PM
SAAMBRAM AKSHAY KUMAR REDDY
SAAMBRAM AKSHAY KUMAR REDDY - avatar
+ 1
I've just run your amended code with 11 words and it work fine. Copy and paste the output you're getting.
12th May 2020, 9:36 PM
rodwynnejones
rodwynnejones - avatar
+ 1
sorry..post deleted...didn't work as expected.
12th May 2020, 9:56 PM
rodwynnejones
rodwynnejones - avatar