Thread: Passing argument of 'sprintf' makes pointer from integer without a cast.

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    69

    Passing argument of 'sprintf' makes pointer from integer without a cast.

    Code:
    char type, letters[4], digits[5];
    char l_plates[M][N];
    
    for (i=0; i<M; i++) {
        scanf(" %c", &type);
        scanf("%3s", letters); 
        scanf("%4s", digits); 
        sprintf(l_plates[i][N], "%s %s %c", letters, digits, type);
    }
    Can someone please explain to me why this isn't compiling and how to fix it?
    I'm getting:

    warning: passing argument 1 of 'sprintf' makes pointer from integer without a cast [enabled by default]
    note: expected 'char * __restrict__ ' but argument is of type 'char'.

    PS: I have included <stdio.h> and <string.h>, this is only part of the code.
    Last edited by Xpl0ReRChR; 11-20-2011 at 10:57 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably meant to pass l_plates[i] rather than l_plates[i][N] as the first argument to sprintf.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    69
    Ah you're totally right, thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 08-28-2009, 07:49 AM
  2. Replies: 17
    Last Post: 08-07-2009, 11:52 AM
  3. Replies: 4
    Last Post: 01-27-2009, 02:33 PM
  4. Replies: 2
    Last Post: 05-21-2008, 02:52 PM
  5. passing arg makes pointer to integer without a cast
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 07-11-2006, 05:37 PM