It's ok i've given up trying to return a value so i've made the function void and just printing the line within the function itself rather than main.
Thank you so much for your help laserlight!
Type: Posts; User: sixstringsgaret
It's ok i've given up trying to return a value so i've made the function void and just printing the line within the function itself rather than main.
Thank you so much for your help laserlight!
Wait that can't be it. oops
I think I know what it might be. I am reading a file as the parameter of both functions within the comStaRatio function and therefore I think the file isn't undergoing rewind() for the second...
Sorry, yes it works fine!
comments:2
statements: 8
therefore .25
I am using Bloodshed Dev-C++
I found something weird... If I print ratio within the function, it works fine but still returns 0.00
Could it be to do with my compiler?
Even if I just set ratio to say 2 and comment out the division, it still returns a 0.00 so it's not a casting error.
I don't know how to illustrate the problem any more simple.
It works with int values but not with float. When I change to float it just always returns 0.00.
I can't see the problem. :(
No I can't say that I do.
The two parameters you have in green are ints yes but comStaRatio returns a floating point number.
Uh oh. Whenever I try to change the function and the function call to float it doesnt work!
float comStaRatio(int comments, int statements)
{
float ratio=1;
...
laserlight you are a legend! I can;t believe i was so stupid not to realise that the answer actually is 0!!!
Thank you!
I'm unsure, but it returns 0.
How do you call a function in a function?
This is the function:
int comStaRatio(int comments, int statements)
{
int ratio=1;
ratio=comments/statements;
I forgot to say that i intend going through the file by 1 position each time
eg:
int number; int another_number;
first: int number //first occurance
second: nt number;
third: t...
All I want to do is search the c file for int, char etc... which are listed in the lookup file and therefore count how many variables are in the c file.
I am reading the c file 10 chars at a time,...
This is what I have now:
int varCount(FILE *a_file)
{
FILE *lookup=NULL;
lookup=fopen("lookup.txt","r");
char curr_var[10];
char c[10];
char *pch;
Error fixed.
How do I search for the string in the c file?
This is what I have so far:
int varCount(FILE *a_file)
{
FILE *lookup=NULL;
lookup=fopen("lookup.txt","r");
char curr_var[10];
I have a .c file and I have a lookup file.
The lookup file is like follows:
¬int
¬short
¬long
¬double
¬float
¬char