I need help converting a code to legible form so that each line of code has the legible form underneath its resspective line. Im reading from a file with a contiguous line of txt which is to be decoded. I know i need a while loop to find the end of line character but im not quite sure how to write it. My code is below
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> main() { char* ptr; /* Declare a pointer */ int i;int shift = -2 ; int STR_LENGTH; int SIZE; /* Declare our variables */ char mystring [150]; /* Declare a string */ FILE * pFile; pFile = fopen ("myfile.txt" , "r"); if (pFile == NULL) perror ("Error opening file"); else { fgets (mystring , 150 , pFile); puts (mystring); STR_LENGTH=strlen(mystring); /* Get the string length */ SIZE=sizeof(mystring); /* Get the sizeof the string */ /* Print out the values */ printf("\n the value in strlen is %d size is %d\n",STR_LENGTH,SIZE); /* Point the pointer at the first element */ ptr = &mystring[0]; for (i = 0; i < STR_LENGTH; i++) /* Set up the loop */ { /* Shift the first character in the string */ *ptr = mystring[i]+shift; ptr++; /* Increment the counter */ } printf("The code is!!\n"); /* Print out the result */ printf("%s",mystring); fclose (pFile); } } The finished program should print like this
K"jcxg"c"oqwvj"."K"fq"pqv"urgcm i have a mouth i do not speak K"jcxg"hqwt"g{gu"."dwv"ecppqv"ugg i have four eyes but cannot see K"jcxg"c"dgf"."dwv"fq"pqv"unggr i have a bed but do not sleep Ecp"{qw"vgnn"og"yjq"K"dgA" you tell me who i be? instead it reads like this with the existing code
K"jcxg"c"oqwvj"."K"fq"pqv"urgcmK"jcxg"hqwt"g{gu"."dwv"ecppqv"uggK"jcxg"c"dgf"."dwv"fq"pqv"unggrEcp"{qw"vgnn"og"yjq"K"dgA" i have a mouth i do not speak i have four eyes but cannot see i have a bed but do not sleep you tell me who i be? im using turboC Any help will be much appreciated!
K"jcxg"c"oqwvj"."K"fq"pqv"urgcm.Is this the Mordor language? :Dchar* ptrdeclares a pointer, but determining what that pointer is used for is a completely different matter.