3 Replies - 942 Views - Last Post: 29 September 2009 - 01:15 AM Rate Topic: -----

#1 jayu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-September 09

c program to read a data from excel

Post icon  Posted 28 September 2009 - 10:17 PM

hi

i have written a c program to read a data from excel .the program is here

#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp;

struct country
{
char countryname[400];
int i;
int c_code;

//int i;
//float bs;
};

struct country e;

fp=fopen("gaya.dat","r");

if(fp == NULL)
{
puts("cannot open file");
exit(1);
}
printf("%s%d",e.countryname, e.c_code);

printf("%s%d",c_code,countryname);
while(fscanf(fp,"%s\t%d",e.countryname,&e.c_code)!= EOF)

printf("\n%s\n\n\t%d\n",e.countryname,e.c_code);

fclose(fp);
return (0);

}


while running the output is coming like this


-Northern_Africa

181

5103

181

-Southern_Africa

181

5104

181

-Western_Africa

181

5105

181

Americas

181

5200

181

-Northern_America

181

5203

181

-Central_America

181

5204

181

-Caribbean

181
the original data is like this

Country_code Country_name

Afghanistan 0002
Albania 0003
Algeria 0004
American Samoa 0005
Andorra 0006
Angola 0007
Anguilla 0258
Antigua and Barbuda 0008
Argentina 0009
Armenia 0001
Aruba 0022
Australia 0010
Austria 0011
Azerbaijan 0052
Bahamas 0012
Bahrain 0013
Bangladesh 0016
Barbados 0014
Belarus 0057
Belgium 0255
Belgium-Luxembourg 0015
Belize 0023
Benin 0053
Bermuda 0017
Bhutan 0018
Bolivia 0019
Bosnia and Herzegovina 0080
Botswana 0020
Brazil 0021
British_Virgin_Islands 0239
Brunei_Darussalam 0026
Bulgaria 002



pls help me in solving this problem to get a data in the above format. The above data is stored in a notepad. I saved tha file as gaya.dat file

Is This A Good Question/Topic? 0
  • +

Replies To: c program to read a data from excel

#2 Guest_c.user*


Reputation:

Re: c program to read a data from excel

Posted 28 September 2009 - 11:06 PM

read numbers like character strings

	while (fscanf(fp, "\t%s\t%s\t", e.countryname, e.c_code) == 2)
	   ;



struct country {
	char countryname[400],
		 c_code[100];
	int i;
};


Was This Post Helpful? 0

#3 jayu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-September 09

Re: c program to read a data from excel

Posted 29 September 2009 - 01:14 AM

View Postc.user, on 28 Sep, 2009 - 10:06 PM, said:

read numbers like character strings

	while (fscanf(fp, "\t%s\t%s\t", e.countryname, e.c_code) == 2)
	  ;



struct country {
	char countryname[400],
		 c_code[100];
	int i;
};


hi

i tried code u sent still output is coming in old format only , any other method is there to read a file from excel. pls help me
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: c program to read a data from excel

Posted 29 September 2009 - 01:15 AM

Please do not create duplicate topics when the orginal topic has replies.

Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1