Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to read ascii data in a file using c

Status
Not open for further replies.

jyothib86

Newbie level 6
Joined
Feb 27, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
mysore
Activity points
1,412
hello every one am new to c can anybody tell me how to read ascii eeg data ..

thanks in adance..
 

Can you post or upload the ascii file you're attempting to read?

You might also include your program as well.
 

Can you elaborate the doubt in detailed....

i have collected eeg data where i have read its 2(time) and 4 (amplitude)column to get the waveform which r in ascii version am attaching the one such data plz suggest me
 

Attachments

  • fifty.TXT
    60.5 KB · Views: 79

i have done it in matlab but i want to try in c also so plz suggest me . i have a eeg data which is in ascii form i need to read 2 (time)and 4 (amplitude)column to plot the signal am attaching the related data .
 

Attachments

  • fifty.TXT
    60.5 KB · Views: 61

in c Asci value reading ,you can take the following method

#include<stdio.h>
void main()
{
int i;
char c;
printf("Enter a Character To convert the ASCI value \n");
Scanf("%c",&C)
i=c;
printf(" the converted ASCII value is is %d",i);
}
 

You dont need any particular logic to read ASCII data....just simply

print the data like

printf("%d ",variable);

so that it prints the data that corresponding to ASCII value..........
 

Trim your data file down to the essential columns:

1,-12.78, -31116, -0.09, -14441, -0.04, -16675, -0.05
2,-12.75, -24519, -0.07, -10620, -0.03, -13899, -0.04
3,-12.73, -18812, -0.06, -7205, -0.02, -11607, -0.03
4,-12.70, -14236, -0.04, -4411, -0.01, -9825, -0.03
5,-12.68, -10850, -0.03, -2366, -0.01, -8484, -0.03
6,-12.65, -8537, -0.03, -1102, -0.00, -7435, -0.02
7,-12.63, -7035, -0.02, -552, -0.00, -6483, -0.02
8,-12.60, -6002, -0.02, -567, -0.00, -5435, -0.02
9,-12.58, -5089, -0.02, -948, -0.00, -4141, -0.01
10,-12.55, -4014, -0.01, -1475, -0.00, -2539, -0.01
11,-12.53, -2616, -0.01, -1948, -0.01, -668, -0.00
12,-12.50, -895, -0.00, -2219, -0.01, 1324, 0.00
13,-12.48, 1005, 0.00, -2208, -0.01, 3213, 0.01
14,-12.45, 2825, 0.01, -1909, -0.01, 4734, 0.01
15,-12.43, 4262, 0.01, -1381, -0.00, 5643, 0.02
16,-12.40, 5038, 0.02, -727, -0.00, 5765, 0.02
17,-12.38, 4981, 0.01, -66, -0.00, 5047, 0.02
18,-12.35, 4074, 0.01, 498, 0.00, 3576, 0.01
19,-12.33, 2482, 0.01, 900, 0.00, 1582, 0.00
20,-12.30, 535, 0.00, 1128, 0.00, -593, -0.00
21,-12.28, -1318, -0.00, 1227, 0.00, -2545, -0.01
22,-12.25, -2594, -0.01, 1285, 0.00, -3879, -0.01
23,-12.23, -2857, -0.01, 1415, 0.00, -4272, -0.01
24,-12.20, -1809, -0.01, 1726, 0.01, -3535, -0.01
25,-12.18, 649, 0.00, 2296, 0.01, -1647, -0.00
26,-12.15, 4390, 0.01, 3154, 0.01, 1236, 0.00
27,-12.13, 9072, 0.03, 4266, 0.01, 4806, 0.01
28,-12.10, 14191, 0.04, 5540, 0.02, 8651, 0.03
...
...
...

Declare a file handle

FILE *my_data;

Use fopen to open file for reading


my_data = fopen (my_filename, "r");


Then use fscanf to read data into predeclared variables

fscanf (my_data, "%f %f %i %i", &f1, &f2, &i1, &i2);

Then close the file using fclose

fclose (my_data);

Example of using these functions:

fscanf()

You can test the fscanf call in a while loop, when it returns null, end loop.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top