helo,
my file r.csv is as follows

07 02 2011
09 05 2011
..
..

i don't know what is error. but the function is not being called..

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>

int calday(float,float);
int main()
{// main start
  FILE *in, *out;
  char *rdf,*wdf;

  char day[10],mon[10],year[10];
  float Day,Mon,Year;

  rdf="A:\\r.csv";
  wdf="A:\\mizoout.csv";

  in = fopen(rdf,"rb");
  out = fopen(wdf,"w");

  if(in == NULL)
  {
    printf("Cannot open input file.\n");
    exit(1);
  }

  if(out == NULL)
  {
    printf("Cannot open output file.\n");
    exit(1);
  }

 fprintf(out,"%s\n","day,month,year");

	while(fscanf(in,"%s %s %s\n,",&day,&mon,&year)>0)
	{ //while start

		Day = atof(day);
		Mon = atof(mon);
		Year = atof(year);

		calday(Day,Mon);

		fprintf(out,"%f,%f,%f\n",Day,Mon,Year);
	} // while end
	printf("\nFile has successfully written");

	fclose(in);
	fclose(out);
	getch();

	return 0;
}//main end

int calday(float day,float month)
{
	if(month == 2)
	{
		day = day + 31 ;
	}
	else if(month == 3)
	{
		day = day + 59;
	}
	else if(month == 4)
	{
		day = day + 90;
	}
	else if(month == 5)
	{
		day = day + 120;
	}
	else if(month == 6)
	{
		day = day + 151;
	}
	else if(month == 7)
	{
		day = day + 181;
	}
	else if(month == 8)
	{
		day = day + 212;
	}
	else if(month == 9)
	{
		day = day + 243;
	}
	else if(month == 10)
	{
		day = day + 273;
	}
	else if(month == 11)
	{
		day = day + 303;
	}
	else
	{
		day = day + 334;
	}
	return(day);

}

How do you know it isn't being called? Line 42 calls the method by you don't accept the return value into anything.

In your while statement on line 35 you are using a %s to get input for a float, I don't know what result this will produce from fscanf, but it is possible that the loop is never entered and that the calday is never called, and even if it is you probably would receive weird results anyway. You should probably use a %f instead of a %s.

A couple things on your statement

while(fscanf(in,"%s %s %s\n,",&day,&mon,&year)>0)

1) you don't need the &. Each variable is already a pointer since they are arrays.
2) >0 is OK if only one of the values is needed. Use =3 if you want all values to be correctly entered.

well this is just an demo of my problem. i am dealing with very large data. so i need to use > 0 only..

i can't use %f as some of the value will be in string.. for example.

07 02 2011
09 03 Notavailable etc..

and there is no problem in while loop..
it is being executed properly but calday function is not being called...

so please tell me what is the problem..

Again I ask how do you know it isn't being called? You are passing the values of day and month by value, you are changing the local version of day then returning it, but you don't accept the return value anywhere thus the method *does nothing*.

okay i got you i guess..
i can write

Fday = calday(day,month);
and returning a day in function..

but this is also not working..
because function is not being called...

because function is not being called...

Prove it. Add printf() statements to prove it's not being called.

In this code, calay is definately being called. calday might be a good place for switch/case.

okay calday is being called.. and returning day to Fday properly now...

what if i want to return month also???

what i have to do to return more than one values??
can i write return(day,month)

Write calMonth()

no i can't create other function. i want to get value from that function only.
can one function return more than one value.?

Hello rjbrjb777,
Try this...
Create a structure with variables dd(for day) and mm(for month). Assign the variables with the values you calculated in the function calday and return the structure instead of 'day' only.

struct cal
{float dd ,mm;
};
cal daymonth,daymonth2;
int  calday(float day,float month)
{   
  if(month==2)
  
  //code as you posted
  else
  {day = day + 334;
  }
  daymonth.dd=day;
  daymonth.mm=month;
  return(daymonth);
}

Use daymonth2 to get the structure having values of day and month that you calculated
in calday in the main function.

Why not pass the address of day and month to calday and return nothing?
void calday(float *day,float *month);

thank you all. my problem has been solved.
regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.