Thursday, July 30, 2009

Simple error in C; printf function.?

This is probably extremely simple and easy, but I can't figure it out, because I usually program in C++. I am getting this error when compiling:





[Warning] passing arg 1 of `printf' makes pointer from integer without a cast





This is my code I use when I get this error, in my function that prints variables.





void printDate(char date[])


{





int n;


for (n = 4; n %26lt; 6; n++)


{


printf(date[n]);


}


printf("/");


int m;


for (m = 6; m %26lt; 8; m++)


{


printf(date[m]);


}


printf("/");


int i;


for (i = 0; i %26lt; 4; i++)


{


printf(date[i]);


}


printf(" at ");


int z;


for (z = 8; z %26lt; 12; z++)


{





printf(date[z]);


}


}














I have no idea why it's screwing up, but if anyone could help me I'd greatly appreciate it :)

Simple error in C; printf function.?
you need to use something like


printf("%c", date[j])


the %c means a variable of type character


i dont know if this is the exact way but its definately he right structure
Reply:the error sounds like you're passing your date, not the address of the date. Without seeing how you call it, its hard to say.
Reply:For printf()





you need the formatted data and then the arguments








Found something to help you:


http://www.cplusplus.com/reference/clibr...
Reply:printf() definition is


printf(char *, ...)


You are trying to call it as


printf(char) which causes this error


I have updated the code so it uses putchar() to output a character.





void printDate(char date[])


{





int n;


for (n = 4; n %26lt; 6; n++)


{


putchar(date[n]);


}


printf("/");


int m;


for (m = 6; m %26lt; 8; m++)


{


putchar(date[m]);


}


printf("/");


int i;


for (i = 0; i %26lt; 4; i++)


{


putchar(date[i]);


}


printf(" at ");


int z;


for (z = 8; z %26lt; 12; z++)


{


putchar(date[z]);


}


}


No comments:

Post a Comment