+ 2

HElp me, what's wrong with this code?

#include <stdio.h> #include <string.h> int ltou(char str[100]); int main() { char str[100]; scanf("%s", str); // Lower to upper case conversion ltou(str[100]); return 0; } int ltou(char str[100]){ int len= strlen(str); for(int i=0; i<len; i++){ if(str[i]>='a' && str[i]<='z') str[i]= str[i]-32; } printf("\n%s", str); return 0; } I'm getting the following error message timeout: the monitored command dumped core ./Playground/runner.sh: line 84: 11 Segmentation fault timeout "$runtime" "$output" - < "/usercode/inputFile" ion] 10 | ltou(str[100]); | ~~~^~~~~ | | | char ./Playground/file0.c:3:15: note: expected 'char *' but argument is of type 'char' 3 | int ltou(char str[100]); | ~~~~~^~~~~~~~

27th Apr 2020, 10:33 AM
Tom
Tom - avatar
5 Antworten
+ 4
Alexander Thiem Yes I checked any way can be used
27th Apr 2020, 10:45 AM
Puthur Harthik
+ 3
HElp me, what's wrong with this code? #include <stdio.h> #include <string.h> int ltou(char str[100]); int main() { char str[100]; scanf("%s", str); // Lower to upper case conversion ltou(str); return 0; } int ltou(char str[100]){ int len= strlen(str); for(int i=0; i<len; i++){ if(str[i]>='a' && str[i]<='z') str[i]= str[i]-32; } printf("\n%s", str); return 0; } //this should work
27th Apr 2020, 10:40 AM
Alexander Thiem
Alexander Thiem - avatar
+ 2
when you call the function you should just give str: ltou(str); otherwise you just give the function element 100 of your string...
27th Apr 2020, 10:39 AM
Alexander Thiem
Alexander Thiem - avatar
+ 1
Puthur Harthik Yes it is just the same, but this was not the mistake...
27th Apr 2020, 10:44 AM
Alexander Thiem
Alexander Thiem - avatar
+ 1
thankyou @Alexander thiem and @puthiur harthik
28th Apr 2020, 2:24 AM
Tom
Tom - avatar