whats wrong with the c code ?? it has to convert string to ASCII values char by char ..
#include
#include
#include
#include
int main()
{
int len,ctr,x;
char str[100],ch;
int c;
puts("Enter the string to be encrypted ");
gets(str);
printf("the entered string is :\t ");
puts(str);
len = strlen(str);
printf("the lenght of the string is : %d \n",len);
for(ctr=0;ctr<=len;ctr++)
{
c = str[ctr];
printf("%d\n",x);
}
return 0;
}
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
OpenStudy (anonymous):
You are overstepping the bounds of the string in the loop. The string ranges from 0 to length-1, hence the equals is not correct.
Also you can directly print the characters inside printf.
#include<stdio.h>
#include<string.h>
int main()
{
int len,ctr,x;
char str[100],ch;
int c;
puts("Enter the string to be encrypted ");
gets(str);
printf("the entered string is :\t ");
puts(str);
len = strlen(str);
printf("the lenght of the string is : %d \n",len);
for(ctr=0;ctr<len;ctr++)
{
printf("%d\n",str[ctr]);
}
return 0;
}