473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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(string1, “done”))
Break;
Printf(“Enter string2: “);
Scanf(“%s”, &string2);
Printf(“String1: %s String2: %s\n”, string1, string2);
Printf(“Returned string : %s\n”, mystrcat(string1,
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.
Nov 7 '06 #1
16 2058
sicarie
4,677 Expert Mod 4TB
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 ;) )
Nov 7 '06 #2
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.
Nov 7 '06 #3
sicarie
4,677 Expert Mod 4TB
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.
Nov 7 '06 #4
allrite where do i start ?
Nov 7 '06 #5
sicarie
4,677 Expert Mod 4TB
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?
Nov 7 '06 #6
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(string1,"done"))
break;

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



my question is --- wats next ?
Nov 7 '06 #7
sicarie
4,677 Expert Mod 4TB
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.
Nov 8 '06 #8
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.
Nov 8 '06 #9
sicarie
4,677 Expert Mod 4TB
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....
Nov 8 '06 #10
sicarie
4,677 Expert Mod 4TB
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')
Nov 8 '06 #11
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 .
Nov 8 '06 #12
sicarie
4,677 Expert Mod 4TB
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!
Nov 8 '06 #13
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
Nov 14 '06 #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
Nov 14 '06 #15
I thought I added a reply this morning.
It appears to have vanished.

everyone seems to be repeating a gross error in your original code:

scanf ( "%s", &string );

if string is an Array: char string[100]; or suchlike,
as an array, it is handled as an Address. It does not need the &.

try scanf ( "%s", string );

JimJ
Nov 14 '06 #16
thanks for your help guys , i managed to get this thing working . thanks a lot .
Nov 17 '06 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
0
by: unixman | last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to posting in the newsgroups for help. :) Simple problem, in theory. Given table "map": CREATE TABLE map ( entry_id...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
6
by: Scott Niu | last post by:
Hi, I have this following simple c++ program, it will produce memory leak ( see what I did below ). My observation also showed that: There will be a mem leak when all the 3 conditions are true:...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
0
by: Mick Hardy | last post by:
Hi, Has anyone seen this weird behaviour or have any suggestions or can anyone reproduce it? The history: I converted a large third party DB from 97 to XP and it uses the...
2
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so...
2
by: Evan | last post by:
Hey, I posted this yesterday, but no one had any ideas? C'mon now, I know this isn't that hard, i'm just a little new to javascript, and I can't quite figure this out. I searched and searched to...
2
by: Michael7 | last post by:
Hi everyone, I'm new to CSS of course, and have been trying to learn it. However, when I try to pull off something as simple as positioning of text . . . nothing works in my index page. So in...
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.