Help me with parallel arrays, loops in C

+1 Ted Maxwell · July 13, 2015
I'm new to The C Programming Language. After seeing thenewboston's videos I started creating this program but I couldn't complete it
/* I'm just making a program that takes user input convert every character in it with
numbers and add it in "ainput" in two array below and then returns that array of characters to user*/
int main()
    char input[1000]; // Input from user
    int i, j;
    int n = 0;
    char one;
    char ainput[1000]; // Array in which crypted text will be inserted
    puts("Give a String!!!");
    // Two arrays with same corresponding numbers of alphabets and numbers like A = 1, B = 2, both arrays work together like a object/dictionary
    char unEncodedText[78] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ',',','?','.','&','#','!','@','','/','-',';',':','$','(',')','*','+','=','_','%','[',']','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','"','\''};
    char encodedText[78] = {'10','20','30','40','50','60','70','80','90','270','110','120','130','140','150','160','170','180','190','280','210','220','230','240','250','260','S0','C0','Q0','P0','A0','H0','E0','T0','L0','G0','N0','F0','Z0','Y0','W0','I0','O0','X0','B0','V0','U0','D0','M0','J0','290','310','320','330','340','350','360','370','380','390','410','420','430','440','450','460','470','480','490','510','520','530','540','550','560','570','K0','R0'};
    // I added zeroes after every number i.e. 10, 20 when they'll be separated with a Decrypteer zeros will mark end of letter like 102030 = 1,2,3 = ABC
    //I wanted to create a file in users pc so I made below code
    FILE * fPointer;
    fPointer = fopen("crypted.txt", "w");
    fprintf(fPointer, input);

    fPointer = fopen("crypted.txt", "a");
    fprintf(fPointer,"\nThis is crypted form \n");
    //below for loop searches for index of a specific element, when user inputs A it will search letter A in unEncoded Text
    //then take its index in this case 0
    // match that index with encodedText array then find that matching code i.e. A = 10
    for(j = 0;5 > 4; j++){
        if(input[n] == unEncodedText[j]){//This matches one letter form whole unEncodedText array
            printf("%d",encodedText[j]);//this prints that code and I think HERES THE PROBLEM IS
            //here j is the index of the letter which user put which was matched with one element of unEncodedText array
            //this index will help us to find matching code in encodedText
            n++;// this orders the if statement to check the next character in user's input
            j = 0;//this resets the j i.e. index if not we'll wrong index right?
            if(input[n] == '\0'){
                break;//when all indexes of users input array are found loop is broken
    // below lines fill and close crypted.txt  
    fprintf(fPointer, ainput);
    // hope so you'll help I'm a begineer I did same with JS so wanted to make my all same JS projects with C href=""
    //most of the time there's 505 on that server that's not my fault but sometime its accessible
    return 0;

Post a Reply


Oldest  Newest  Rating
0 Jon Z. · July 15, 2015
Have you done any progress?
PM me if you need help.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator