Hello fellow programmers,
I am way new to C programming, but not programming itself. Been coding PHP for quite a while. C seems to be a very promising language, therefore I would like to get my deeper sight in it.
However I have came up with a problem that I cannot figure how to solve. I bet it is a easy task to do, somehow I just can't handle it on my own.
I am posting a shortened version of my code, it's obvious that you don't need it all.
Here is the main program:
and here is a shortened version of spaces.hCode:#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "spaces.h" int main() { char *tekstas = file_get_contents("duomenys.txt"); int *spaces = countspaces(tekstas); return 0; }
When my program is using countspaces function I get the following warning: <...>spaces.h [Warning] return makes pointer from integer without a castCode:int *countspaces(char *buff) { int i; int spaces = 0; for(i = 0; i < strlen(buff)-1; ++i) { if(isspace(buff[i]) && isspace(buff[i+1])) { spaces++; } } return spaces; }
Can anyone tell me how do I solve this warning and explain why (so that I wouldn't have this question again)?
Thank you in advice,
Faifas
Edit: I have solved this issue. All I had to do is remove pointers, so the fixed code is the following:
main program:
and spaces.h is now:Code:#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "spaces.h" int main() { char *tekstas = file_get_contents("duomenys.txt"); int spaces = countspaces(tekstas); // no pointer return 0; }
Code:int countspaces(char *buff) // no pointer also { int i; int spaces = 0; for(i = 0; i < strlen(buff)-1; ++i) { if(isspace(buff[i]) && isspace(buff[i+1])) { spaces++; } } return spaces; }



LinkBack URL
About LinkBacks


