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:
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);
return 0;
}
and here is a shortened version of spaces.h
Code:
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;
}
When my program is using countspaces function I get the following warning: <...>spaces.h [Warning] return makes pointer from integer without a cast
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:
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;
}
and spaces.h is now:
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;
}