My exposure to arrays and pointers are bit limited. And concatened strings even less ( it was not covered in my class so I had to google it. ) So I know there are errors. I can not use any of C string libary functions. Thoughts?

#include <stdio.h>

char *strcat385(char string1[ ], char string2[ ]) {
int i = 0;

while(str[i])

{
string1[i] = str[i];
++i;
}

++i;

while(str2[])

{

string1[i] = strign2[];

++i;
}



string1 [i] = '\0';


}

int main( ) {
  char str[50] = "CSC course 385 ",
       str2[ ] = "sections 701, 710";
  printf("The return from strcat373:\n%s\n", strcat(str, str2));
  printf("string1 is %s\nstring2 is %s\n", str, str2);
}

Recommended Answers

All 2 Replies

1. Use code tag correctly:
[code=c] source

[/code]

2. Have you ever heard that all names must be declared before used in C? If not, take your textbook again. If yes, what's str (or str2) in strcat385 body?

3. What's an index of string2 element in string1[i] = strign2[]; ? Can you explain what is it: while(str2[]) ?

4. I see that strcat385 must return a pointer. Where is return statement in this function body?

It's hard to say that absolutely senseless and untidy text demonstrates your efforts...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.