Monday, May 24, 2010

If know C language then solve it.....?

write a program to transform its input according to a specified transformation scheme. the transformation scheme will consist of two strings: a string of character and then a string of replacement characters. the idea is that your program replaces every instance of the ith character in the initial string with the (i+3) character (of english alphabets) in the replacement string. when no substitution is defined for a character , the program just passes it through to the output unchanged. The program should inform the user of any errors in the transformation scheme. Your program should display the phrase before and after the substitutions have been made.





example : This is a C program.


string after the transformation : Wklv lv d f Surjudb.

If know C language then solve it.....?
Here is a source code i have enclosed below.Copy and paste it in a new text file and compile it.





If it is not upto your needs dont worry . Contact me at m_gopi_m@yahoo.co.in. I really like to program like this.





But time doesn't support me and i was not able to understand the question clearly. So if you want contact me and i can design new program.





Here the source begins.......





/*


Please create a new folder and place this program in it. It creates


Two text documents(first.txt and second.txt).





first.txt is a copy of the input stream.


second.txt is a copy of encryption.


repalaces ith term by i+3 terms.





Please do not use any special keys like delete,backspace etc...





If you want to change the encryption number. Change 'num' variable(int)


present at 23:14.


*/








#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


FILE *fp1,*fp2;


char a,b;


int num=3,i;





clrscr();


printf("\n\nEnter your message:\n%26lt;When you do so press enter%26gt;");


printf("\n%26lt;Please avoid special characters%26gt;\n\n\t");





fp1=fopen("first.txt","wt+");


while(a!=13)


{


a=getche();


if(a==0)


{


getch();


printf("\b\a");


}


else if(a==8)


{


printf("%c\a",b);


}


else


{


fputc(a,fp1);


b=a;


}


}


rewind(fp1);





fp2=fopen("second.txt","wt+");


while(a!=EOF)


{


a=fgetc(fp1);





if(a!=EOF %26amp;%26amp; a!='\0')


{


if(a!=' ')


a+=num;


fputc(a,fp2);


}


}


fclose(fp1);





rewind(fp2);


clrscr();


printf("\nThe resultant text is\n\n\t");





a=' ';


while(a!=EOF)


{


a=fgetc(fp2);


printf("%c",a);


}





gotoxy(1,22);





for(i=0;i%26lt;68;i++)


printf("%c",205);


printf("\nFor convenience the input data is saved in first.txt");


printf("\nThe encrypted data is saved in second.txt");


printf("\nPlease take a view at it.");





getch();


fclose(fp2);


}
Reply:That's not a hard task.


All we need is an array, or you can called: matrix.


In ANSCI behind every character there is a number.


For example: A-97,B-98(just assume, i dont have a manual now on hand), then you should design a number array, such as : {1,2,5,6}, then you could process the string with such method: the first charac. add the array[1], then the second add the array[2], and make a simple recycle, to let the string to add the members of array in a round turn.


Relly simple, right?
Reply:i will not write program for u.





But make an array of 26 characters.





take every character from given string and get the position no.


then add two and get the string





Do it untill all the characters completed.


And yes dont forget to skip to 1 if count increase to 26.





simple.

nobile

No comments:

Post a Comment