Thread: Am I conatenating these strings correcting

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    16

    Am I conatenating these strings correcting

    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 use my book. ) So I know there are errors. I can not use any of C string libary functions. Thoughts?




    Code:
    #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);
    }
    Last edited by uscuba2; 04-11-2009 at 02:20 PM.

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Code:
    while(str[i])
    str hasn't been declared in that scope, same for str2.

    Your function doesn't return a value, but it's supposed to return a char *.

    Code:
    printf("The return from strcat373:\n%s\n", strcat(str, str2));
    The function you are writing is named strcat385()...

    Main returns an int, try using

    Code:
    return 0;
    at the end of the main function.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM