I am getting this problem in C programming. I’m new to C so I would like some help.
Anyine know why this is happening?
I’m trying to get the dir path using getcwd and I’m not even formatting so I don’t get why I’m getting this warning? My code is below:
replace.c: In function ‘main’:
replace.c:49:8: warning: too many arguments for format [-Wformat-extra-args]
printf("Search begins in current folder: ",
getcwd(currDir,
sizeof(currDir)), "n");
2
Answers
The format string in the call of printf does not contain conversion specifiers. So the second and the third arguments apart from the format string are redundant.
It seems you forgot to include the conversion specification
%s
in the format string.For example
Pay attention to that the call of getcwd can return a null pointer. So you need to check the return value before using the call of printf.
You are trying to print the
getcwd()
function inside of theprintf()
function. That is why it is issuing a too many arguments error. If you want to get the current working directory using agetcwd()
, then you can try using this code: