RSS Forums RSS
Please support our C++ advertiser: Programming Forums

total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast"

Join Date: Apr 2005
Location: Dallas
Posts: 8
Reputation: atrixnet is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
atrixnet's Avatar
atrixnet atrixnet is offline Offline
Newbie Poster

Help Re: total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast

  #10  
Apr 23rd, 2005
Originally Posted by prog-bman
Of course there is. Like dave and prelude saud you have to use the char* type.
e.g
#include <stdio.h>
#include <string.h>

char *getSomeString(void);

int main(void)
{
    char mainString[strlen(getSomeString()) + 1];
    strcpy(mainString,getSomeString());
    printf("%s",mainString);
    getchar();
}

char *getSomeString(void)
{
    return "Some String";
}
Now I think I did the printf right I am a C++ man

Ok but i'm still in the dark, I'm sorry. If you say char *getSomeString... you aren't really returning a string, you're returning a pointer right? DOH!

And is it bad to say...
char mainString[] = getSomeString();

My Oreilly book says...
C has a special shorthand for initializing strings: Surround the string with double quotes to simplify initialization...
char name[] = "Sam";
The dimension of name is 4 because C allocates a place for the '\0' character that ends the string.
Reply With Quote  
All times are GMT -4. The time now is 9:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC