One simple help........

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marsguy85
    New Member
    • Oct 2006
    • 27

    One simple help........

    hi all i am a new bee for ANSI C , can anyone solve the question for me please , so that i can understand each line of it wid puting time into it , i really want to get ANSI C in my head so kindly help me out .
    cheers.





    A function with the following prototype

    Char *mystrcat(char *s, char *p);

    The function appends string p to the end of string s and returns a pointer to the start of string s.
    Remember that strings are terminated by binary zero (‘\0’).

    Suppose string s contains “abcd” and string p contains “xyz”. The result would be string s containing “abcdxyz”.

    Use the program section below to test your program:
    #include <ctype.h>

    char *mystrcat(char *s,char *p);

    main()
    {
    Char string1[80], string2[80];
    For ( ; ; )
    {
    Printf(“Enter string1: “);
    Scanf(“%s”, &string1);
    If (!strcmp(string 1, “done”))
    Break;
    Printf(“Enter string2: “);
    Scanf(“%s”, &string2);
    Printf(“String1 : %s String2: %s\n”, string1, string2);
    Printf(“Returne d string : %s\n”, mystrcat(string 1,
    string2);
    Printf(“String1 : %s String2: %s\n”, string1, string2);
    }
    }

    Hint : ctestchar = *(ptrstring++) – assigns the character pointer to by ptrstring to the character ctestchar and moves the pointer on by one character.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Marsguy-

    What have you tried on this? What parts are you having touble with?

    (you're more likely to get help if you ask a question, and it doesn't look like we're just doing your homework for you ;) )

    Comment

    • marsguy85
      New Member
      • Oct 2006
      • 27

      #3
      Well as i said that i am a new bee and will understand it only after i go throu the code for it . I was honest in saying it and not making up excuses . If u dont want to help then its ok friend.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by marsguy85
        Well as i said that i am a new bee and will understand it only after i go throu the code for it . I was honest in saying it and not making up excuses . If u dont want to help then its ok friend.
        I'm not saying I don't want to help, but you have asked no questions, it looks like you have just posted your homework problem up, and - I'm sorry - I am not going to just give you the code, though if you try it, actually have your own question (like "where do i start" is a valid question), then I'd be more than happy to respond. If you're willing to learn it, i will do everything I can to help you do that, but it looks as if you haven't even bothered to try the question, you just want to get the answer with as little thought and effort as possible.

        Comment

        • marsguy85
          New Member
          • Oct 2006
          • 27

          #5
          allrite where do i start ?

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by marsguy85
            allrite where do i start ?
            You have to define your problem. You have yet to ask a question, and most of your code looks right. Right now you have an empty for loop at the beginning. I'm not sure why this is in a for loop, it looks more like it should be in a while loop ("while" the strings are different). All that having been said, there is no question being asked. The code looks pretty good, though I haven't run it, as it is in an empty for loop, and that alone would break it.

            If it's just compiling, the only syntax error I see is the for loop, you should figure out what you want there and get it working, then see what's going on.

            What are you having trouble with? Is it not compiling? Can you not figure out what to put in the for loop? Are you looking to understand what each of the lines means?

            Comment

            • marsguy85
              New Member
              • Oct 2006
              • 27

              #7
              so far i have been able to write ----------


              #include<stdio. h>
              #include<conio. h>
              #include <ctype.h>
              #include<string .h>

              char *mystrcat(char *s,char *p);
              int main()
              {
              char string1[80], string2[80];
              for( ; ; )
              {
              printf("Enter string1: ");
              scanf("%s", &string1);


              if (!strcmp(string 1,"done"))
              break;

              printf("Enter string2:");
              scanf("%s", &string2);
              printf("String1 : %s String2: %s", string1, string2);
              printf("\n");
              printf("Returne d string : %s\n", mystrcat(string 1,string2));
              printf("String1 : %s String2: %s\n", string1, string2);
              getch();
              }
              return 0;
              }



              my question is --- wats next ?

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Ok, in what sense. What part are you having trouble with?

                I'm sorry, but I don't think you wrote that code yourself, and if you can't even try, I won't either.

                Comment

                • marsguy85
                  New Member
                  • Oct 2006
                  • 27

                  #9
                  Just u answer to there --- i did that , and i dont think u can help coz u know nothing and jst here to fool around wid new bee like me , u are a nerd.

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    Whatever you say man, I know nothing even though I pointed out a glaring syntax problem in your code that you have yet to fix - as well as the fact that

                    YOU HAVE YET TO ASK A QUESTION ABOUT THE CODE

                    you just say 'finish this' or 'what is next'. I'm not your slave, and I'm not going to do your work for you. (and I am proudly a nerd - that's why I make the big bucks now)



                    PS - "what is next" would be to fix that for loop.

                    Like I said three or four posts ago....

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #11
                      Actually what is next is to get you working on the right part.

                      You don't want a main statement. There is no reason for it. (that's why you don't copy code) You want to create the method mystrcat(). You should start out with the function prototype that was given to you, and get it to return a string.

                      Eventually, you will declare that in your teacher's code (either above or below the full main statement, but not inside), and fill in values in the for loop for testing. If you want to do it right now, just to be able to compile it, I'd start low - int i =0;i<2;i++. That way you can get two rounds of input, though you're probably going to fail after 1 the first couple of times (just until you get the bugs out).

                      After you do the first paragraph, you should parse through a string and find the '\0' symbol at the end, and do that to one of the strings that is passed. Then you can either go through letter by letter and add the second, or point to it.

                      (Seeing as how you didn't include the teacher's full requirements, a good question would have been, 'how do i start on the mystrcat method')

                      Comment

                      • marsguy85
                        New Member
                        • Oct 2006
                        • 27

                        #12
                        you missing the whole point .... u r not my slave , all i asked for was help and not your arrogant talks . no one forced u too help me .

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #13
                          Originally posted by marsguy85
                          you missing the whole point .... u r not my slave , all i asked for was help and not your arrogant talks . no one forced u too help me .
                          And I'm trying to (see above), but you're not putting forth ANY effort. If you could have simply said "help me with mystrcat" this discussion would have been much shorter!

                          Comment

                          • JimJoyce
                            New Member
                            • Nov 2006
                            • 3

                            #14
                            char a;
                            int i;
                            scanf ( "%c, %i", &a, &i ); // Correct

                            char string [ ];
                            scanf ( "%s" , &string ); // INCORRECT

                            string MUST NOT be preceeded with an ampersand '&'
                            An array-name IS AN ADDRESS.

                            scanf ( "%s", string ); ?? Correct

                            Comment

                            • JimJoyce
                              New Member
                              • Nov 2006
                              • 3

                              #15
                              char a;
                              int i;
                              scanf ( "%c, %i", &a, &i ); // Correct

                              char string [ ];
                              scanf ( "%s" , &string ); // INCORRECT

                              string MUST NOT be preceeded with an ampersand '&'
                              An array-name IS AN ADDRESS.

                              scanf ( "%s", string ); //Correct

                              Comment

                              Working...