1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Having problem.....

Discussion in 'C' started by Fatima Khan, Feb 21, 2010.

  1. Fatima Khan

    Fatima Khan New Member

    Joined:
    Feb 20, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pakistan
    A program that inputs one string of max length of 10. If the string is identical to "Virtual",
    output the message "Correct Password"; otherwise, output the first four characters in the
    message and the length of the message.
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    You'll have to give some more details.
     
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    is this what you want?

    Code:
    
    #include <stdio.h>
    #include <string.h>
    
    int main(){
    char data[10];
    char temp[4];
    char message[]="Correct Password";
    printf("\ngive me data:");
    scanf("%s",&data);
    if (strcmp(data,"Virtual")==0){
        printf("%s",message);
    }else{
        strncpy(temp,message,4);
        temp[4]='\0';
        printf("%s",temp);
        printf("\nlength=%d",strlen(message));
    }
    
    getchar();getchar();
    return 0;
    }
    
    
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Doing people's homework for them is less help than you think. It doesn't help them learn. They enter a good program so the teacher doesn't see that they're struggling. They delude themselves when they look at the program and think they could have figured it out (they didn't, and they couldn't, otherwise they would have done. But it looks easy when you see it done). Fast forward to the exam where they have no access to the internet: they will not have developed programming ability and will fail. Or if they do have access to the internet and you do their exam for them then they pass, but give employers (who are not so easily fooled) one more reason to discount academic results as nonsense because here's this twit with a pass grade who can't program. So by all means help people, but not by giving them completed code. If you could learn by looking at completed code samples then that's what the teachers would give out in the first place; they don't give you programming assignments just because they're sado-masochists, but because they know you LEARN programming by DOING programming.
     
  5. vivekraj

    vivekraj New Member

    Joined:
    Feb 23, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    If the word entered i equal to virtual,we need to print "Correct Password".Else,what you want to do?You want simple to print the first four characters of the message such as Corr and what you mean the length of the string.Is it 4 or what?Explain it correctly..........
     
  6. sganesh

    sganesh New Member

    Joined:
    Feb 19, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    I think this code will solve your problems,
    I did some of the modification in the program.
    Code:
    #include <stdio.h>
    #include <string.h>
    #include<malloc.h>
    
    int main(){
    char *data = (char *)malloc(10);
    char *tmp;
    char temp[4];
    char message[]="Correct Password";
    data=getpass("\nGive me data:");
    int len=strlen(data);
    if (strcmp(data,"Virtual")==0){
        printf("%s",message);
    }else{
        strncpy(temp,data,4);
        temp[4]='\0';
        printf("Your password is wrong\n Data:%s length:%d\n",temp,len);
    }
    
    return 0;
    }
    
    
    
    
     

Share This Page