+ 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; }
18 Respostas
+ 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
+ 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;
}
+ 4
Thanks Arsenic
+ 4
Thanks I Am AJ !
+ 3
Parthik Sonagara it is deprecated due to security issue with buffer overflows.
+ 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.
+ 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.
+ 1
Parthik Sonagara
Will work here also but gets() function now deprecated means no longer use.
+ 1
I Am AJ !
Ok thanks
Do you know why?
+ 1
Yes it is\0
0
I don't know
0
no
0
Hello bro 2=$ *6/9
0
Printf statement should be outside of while
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
- 1
Bina mistake kr to aadmi aadmi nhi bnta fir to ye code hai galtiyan hoti rhti hai.
Bolo jai shree ram🔥🔥🙏🙏🕉️🕉️♥️♥️