Thread: Code review needed

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    3

    Question Code review needed

    Hello there. This is a small program that reads a line from the screen, takes the ASCII values from the entered text, and edits it. Next, the ASCII values are reintepreted(am i misspelling?) as text, and displayed. However, my final output has (allways?) at least 7 characters, even if you enter only one. I'm allso trying to accomplish, that the part of the string which isn't filled, will be printed empty. In spaces.

    compiled with -std=c99.

    Code:
    #include <stdio.h>
    
    int main(){
        int maxsize;
        printf("How long is your message?\n");
        scanf("%d",&maxsize);
        int iinput[maxsize], ioutput[maxsize], key, c;
        char cinput[maxsize], coutput[maxsize];
        
        printf("What is the message you want to (de)code?\n");
        scanf("%s",cinput);
        for(int i=0;i<maxsize;i++){
            iinput[i]=(int)cinput[i];
        }
        printf("Thank you. ");
        printf("What is your key?\n");
        scanf("%d",&key);
        lchoice:
        printf("1 for coding, 2 for decoding.\n");
        scanf("%d",&c);
        switch (c)
        {
            case 1:
                for(int j=0;j<maxsize;j++){
                    ioutput[j]=iinput[j]+key;
                }
                for(int k=0;k<maxsize;k++){
                    coutput[k]=(char)ioutput[k];
                }
                break;
            case 2:
                for(int j=0;j<maxsize;j++){
                    ioutput[j]=iinput[j]-key;
                }
                for(int k=0;k<maxsize;k++){
                    coutput[k]=(char)ioutput[k];
                }
                break;
            default:
                printf("You did not enter 1 or 2.\n");
                goto lchoice;
        }
        printf("This is the coded message:\n");
        printf("%s\n",coutput);
        system("pause");
        return(0);
    }
    I would really appreciate some help. Thanks in advance.
    Last edited by BramvandenH; 05-10-2013 at 05:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get a code review
    By Richardcavell in forum C Programming
    Replies: 42
    Last Post: 03-19-2011, 10:36 PM
  2. C Code Review
    By trillianjedi in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 06-18-2008, 12:29 PM
  3. review this code
    By KIBO in forum C Programming
    Replies: 12
    Last Post: 08-14-2007, 02:28 PM
  4. Code Review
    By Thantos in forum C Programming
    Replies: 8
    Last Post: 03-06-2004, 06:20 PM
  5. Code review please
    By Brighteyes in forum C Programming
    Replies: 9
    Last Post: 03-29-2003, 06:28 PM

Tags for this Thread