Thread: Strncpy

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    103

    Strncpy

    I am having trouble with the strncpy. Here's my current code for one of my functions that contains the errors:


    Code:
    #include <stdlib.h>
    int extractFirst(char functionRead, char *plusPointer) {
    	char firstNumberString[600]="a;sdlkfasdf";
    	strncpy(firstNumberString, functionRead, plusPointer);
    	return 0;
    }
    These are the errors that I get when I compile with GCC:
    Code:
    dhaivat@DebianDesktop:~/Desktop/Math Engine$ clear
    
    dhaivat@DebianDesktop:~/Desktop/Math Engine$ gcc main.c FunctionParser.c Add.c ExtractNumbers.c -o Math
    ExtractNumbers.c: In function ‘extractFirst’:
    ExtractNumbers.c:4: warning: incompatible implicit declaration of built-in function ‘strncpy’
    ExtractNumbers.c:4: warning: passing argument 3 of ‘strncpy’ makes integer from pointer without a cast
    dhaivat@DebianDesktop:~/Desktop/Math Engine$
    I don't understand what is going wrong. I think I am using the function correctly, right?

    Please help, Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include<string.h>
    Any time you see "implicit declaration", you're trying to use a function before it knows about that function.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    The third argument of strncpy is a number of the integer kind. (One of your other warnings beside what quzah said.)

    That doesn't mean that you have to change extractFirst's signature necessarily, but I can recommend a replacement for strncpy when I know what you're really doing. What's extractFirst supposed to do?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why is strncpy segfaulting here?
    By Calef13 in forum C Programming
    Replies: 3
    Last Post: 12-29-2008, 03:27 PM
  2. Replace strncpy with snprintf, how?
    By garton in forum C Programming
    Replies: 19
    Last Post: 09-11-2008, 03:21 AM
  3. strncpy adavnced :P
    By Joke in forum C Programming
    Replies: 3
    Last Post: 07-14-2008, 11:14 AM
  4. strncpy question, size -1??
    By fayte in forum C Programming
    Replies: 16
    Last Post: 03-16-2006, 11:32 PM
  5. strncpy doesn't seem to work
    By linucksrox in forum C++ Programming
    Replies: 3
    Last Post: 09-08-2005, 01:34 PM