Thread: strcpy, pointers, and help

  1. #1
    Registered User
    Join Date
    Mar 2002

    strcpy, pointers, and help

    I've searched and then read almost every post I could find about these subjects, but just cannot get anywhere on my program.

    list insertAfter (list x, char *s) {
    	//Insert a new element containing s after the current element.
    	//Make the new node the current node.
    	listNodePtr temp = (listNodePtr) malloc(sizeof(listNodePtr));
    	char *tempString;
    	printf("%d is the length of s\n", strlen(s));
    	tempString = malloc(strlen(s) + 1 );
    	strcpy(tempString, s);
    	printf("we are trying to INSERT:  %s\n", s);
    	if (x -> currentNode != NULL && x -> currentNode -> nextNode != NULL) {
    		strcpy(temp -> data, tempString);
    temp -> data is a char*. I get an error whenever I try to:
    strcpy(temp -> data, tempString). I get the idea of what I need to do, I just cannot figure it out for the life of me. Help!

  2. #2
    Registered User
    Join Date
    Mar 2002
    I love the wealth of knowledge on this board. I can't believe my hours of working out that problem was just solved by a function I didn't even know about!

    Thank you very much.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    strdup is not an ANSI-C function.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed