Can anyone find mistake in this code ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone find mistake in this code ?

#include <stdio.h> int main() { int i=0; char a[100]; printf("enter uppercase word to convert in to lower case:-\t"); gets(a); while(a[i]!='/0') { if(a[i]>='A' && a[i]<='Z') { a[i]=a[i]+32; } i++; printf("\n lower case word is:%s",a); } return 0; }

28th Feb 2021, 5:00 AM
Parthik
Parthik - avatar
18 Answers
+ 10
Here are the list of things you did wrong 1) gets() is deprecated (use fgets() or scanf for taking input) 2) Used '/0` instead of '\0' ( as pointed out by I Am AJ ! ) 3) putting final output inside the loop ( not necessarily an error but looking at program I don't think that was what intended to be done here ) Here's the fix 👇 https://code.sololearn.com/cnyw3N9AONfg/?ref=app
28th Feb 2021, 5:10 AM
Arsenic
Arsenic - avatar
+ 7
Parthik Sonagara There is '\0' not '/0' Use fgets instead of gets #include <stdio.h> #define MAX_LIMIT 100 int main() { int i=0; //char a[100]; printf("enter uppercase word to convert in to lower case:-\t"); //gets(a); char a[MAX_LIMIT]; fgets(a, MAX_LIMIT, stdin); while(a[i]!='\0') { if(a[i]>='A' && a[i]<='Z') { a[i]=a[i]+32; } i++; printf("\n lower case word is:%s",a); } return 0; }
28th Feb 2021, 5:05 AM
A͢J
A͢J - avatar
+ 4
Thanks Arsenic
28th Feb 2021, 5:27 AM
Parthik
Parthik - avatar
+ 4
Thanks I Am AJ !
28th Feb 2021, 5:27 AM
Parthik
Parthik - avatar
+ 3
Parthik Sonagara it is deprecated due to security issue with buffer overflows.
28th Feb 2021, 11:51 AM
Théophile
Théophile - avatar
+ 2
Parthik Sonagara When everything updates in the world then programming languages also get updates. New features comes and old features deprecate. That's why same for gets.
28th Feb 2021, 11:48 AM
A͢J
A͢J - avatar
+ 2
28th Feb 2021, 11:57 AM
Parthik
Parthik - avatar
+ 1
Arsenic in your code, there is still a possibility to have a buffer overflow (due to scanf). But you can do : scanf("%99s", a); It will take at maximum 99 chars.
28th Feb 2021, 10:27 AM
Théophile
Théophile - avatar
+ 1
The code runs just fine in other app with gets() why is it happening Arsenic Théophile I Am AJ !
28th Feb 2021, 11:19 AM
Parthik
Parthik - avatar
+ 1
Parthik Sonagara Will work here also but gets() function now deprecated means no longer use.
28th Feb 2021, 11:21 AM
A͢J
A͢J - avatar
+ 1
I Am AJ ! Ok thanks Do you know why?
28th Feb 2021, 11:35 AM
Parthik
Parthik - avatar
+ 1
Yes it is\0
1st Mar 2021, 2:50 PM
Ankit Kumar
Ankit Kumar - avatar
0
I don't know
1st Mar 2021, 3:31 PM
Saeed Hayati
Saeed Hayati - avatar
0
no
1st Mar 2021, 10:48 PM
heera lal yadav
heera lal yadav - avatar
0
Hello bro 2=$ *6/9
1st Mar 2021, 10:49 PM
heera lal yadav
heera lal yadav - avatar
0
Printf statement should be outside of while
2nd Mar 2021, 4:59 AM
srikanth vuppala
srikanth vuppala - avatar
0
srikanth vuppala yeah i figured it out later if we use this structure then output will show conversation of uppercase to lowercase latter by latter
2nd Mar 2021, 5:04 AM
Parthik
Parthik - avatar
- 1
Bina mistake kr to aadmi aadmi nhi bnta fir to ye code hai galtiyan hoti rhti hai. Bolo jai shree ram🔥🔥🙏🙏🕉️🕉️♥️♥️
1st Mar 2021, 2:24 PM
Vɪя͢ʊ͋S͚ジ
Vɪя͢ʊ͋S͚ジ - avatar