C help required
Results 1 to 6 of 6

Thread: C help required

  1. #1
    Senior Member
    Join Date
    Dec 2001
    Posts
    134

    C help required

    The problem that needs an explanation is:
    If in statement 1( marked in red with the arrow) more than one character are entered then statements 2,3 and 4 ( all marked in red with the arrows) are not asked to the user, but the result is shown by the statement 5.

    Suppose, if seven characters are entered during statement 1, then first character will be stored in the variable t, and rest of the six characters are taken up by string s, and then the result is shown normally.
    If only one character is entered in the statement 1, then everything works fine.
    The six extra characters that are entered in the statement 1 are not discarded, but are taken up by the scanf statement (statement 3).





    /* YOUR HELP IS REQUIRED */
    #include<stdio.h>
    int main()
    {
    int i=1;
    int a,j;
    int b;
    char t;
    char s[45];
    clrscr();
    printf("\n\t\t\tHello!!! This is The code\n");
    b=sizeof(a); /*The working of the "sizeof" operator is shown"*/
    printf("%d",b);
    printf("\nEnter any character/s:");
    t=getchar();
    if(t==121 || t==89)/*Checking the values using the ASCII values*/
    {
    printf("You Are getting out of the CODE RED, as you have entered\n");
    }
    else
    {
    printf("\aYou are NOT getting out of the CODE RED as U have typed:\n");
    }
    printf("\t\t\t\t\t%c",t);

    printf("\nEnter the value/ string:\n");
    scanf("%s",s);
    printf("%s",s);
    while(s[i]!='\0') /*finding the lenght of the string without "strlen" function*/
    {
    i++;
    }
    printf("\n The length of the string is: %d",i);
    /*conversion from lower case to upper case without "toupper" function.*/
    for(a=0;a<i;a++)
    {
    for(j=96;j<=122;j++)
    {
    if(s[a]==j)
    {
    s[a]-=32;
    }
    }
    }

    printf("\nThe uppercase of the string is:\n\t\t\t\t %s",s);
    getch();
    return 0;
    }
    ---------------------------end of code---------------------------------

    I need to know about the explanation about, how the compiler is doing all this.
    Please try to run the above code for more clarity, and before doing so remove the number within the brackets and the arrow along with it ( and the brackets too).

  2. #2
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    Ummm... I don't see any red text, and I'm not colour blind.
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  3. #3
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    sorry,, the color did not appeared, i will send the other modified thread.
    U get What U pay for.

  4. #4
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    Just edit this one.
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  5. #5
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    the new thred has been posted
    ,, sorry for using more space.

    i have edited the thread Striek,,, I hope that makes more clear.
    U get What U pay for.

  6. #6
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    I have done the need full, in this particular thread, Please ignore the other thread " c help".
    U get What U pay for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •