Trouble with pointers, ascii values, and string manipulation
Hi, i'm pretty new to programming (as you will see), and i'm having difficulty with this program that takes a string and adds a number (i) to each character's acsii value based on its index in the string (i). For example, the string "aaaaa" would become "abcde".
Here's the code:
Code:
#include <stdio.h>
#include <string.h>
main()
{
char *origin;
int sLimit = strlen(origin);
int i;
printf("Enter a string to encode.\n\n");
scanf("%s",origin);
for (i=0;i<sLimit;i++) {
printf("Value %i: %i\n", i, origin[i]+i);
}
}
The program successfully complies, but when i enter the string "aaaa", i get the following output:
Enter a string to encode.
aaaa
Value 0: 97
Value 1: 98
Segmentation fault
Any help would be appreciated!