Here's my program that asks a user to enter a line of text and then shows the ASCII code it's associated with, and than after that it modifies the ASCII code by adding plus 1 to i, and it also prints out the new character associated with that new ASCII code.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
char s[ 70 ]; // define character array of size 70
size_t i; // loop counter
// use gets to get text from user
puts( "Enter a line of text: a
" );
fgets( s, 70, stdin );
// convert each character to ASCII and output
puts("
ASCII code for the characters
");
for ( i = 0; s[ i ] != ''; ++i )
{
printf(" %c:%d",(s[ i ]),(s[ i ]));
} // end for Uppercase ASCII
// convert each character to modified ASCII and output
puts( "
The line modified with progressively higher ASCII:
" );
for ( i = 0; s[ i ] != ''; ++i )
{
printf( "%c", ( s[ i ] + (i+1)) );
} // end for modified characters
puts("");
printf( "
modified ASCII code for the entered string
a");
for ( i = 0; s[ i ] != ''; ++i )
{
printf( " %c:%d",(s[ i ] + (i+1)),(s[ i ] +(i+1)));
} // end for modified ASCII code
printf( "
The final value of loop variable 'i' is:%d
", i);
puts( "" );
system("PAUSE");
}
I'm having difficulty modifying it so that the ASCII code and characters change by the first seven prime numbers 2,3,5...17 and than after those first 7 prime numbers are up go in reverse 17,13,11,7,...2. So after the first loop say g has ASCII code 103, the modified ASCII code will now be 105 and the new letter will now be i. Can anybody help me out?
See Question&Answers more detail:os