Help me !
I want to write code read file txt and I want to get each value of arry in file txt,
but I don't know get it !
ex : In my file txt have :

10/30/2010 10:42:48 PM                19,955.40                19,996.19                20,745.54                3,822.54                28,418.70                32,576.54                2,632.80                468.79                252.42                20.09                73,121.67                6,594.94                3,476.08                737.20                3,040.86                15,740.80                692.31                19,500.00

I want get each value in file, when I run code , I only one display : 10/30/2010 10:42:48 PM, 3,040.86 - 73,121.67 or I want to diplay any value I like !
And each value I can use to Addition(+), Subtraction(-), multiply(*), division(:)

I only know code read file, about Array I'm verry bad !
my code : http://www.4shared.com/file/T3jR-BU5/readfile.html

I have a line and 19 values in row !
I want to get each values of array,
to calculate
ex : arr[1] + arr[10] or arr[5] + arr[6]....
please help me get each values of array !

Kim, the arrangement of the data, makes this quite awkward.

A normal arrangement might be:

data/time string
number1
number2
number3
...
etc.
Which is very easy to retrieve from a file, put into an array, etc.

It's VERY unusual to have a row of data that's over 450 char's in length!!

Anyway, this shows how you can get the data (there is one string and 18 numbers), from the file. I've run this through your 1 row of data a few times, but I have not really tested it, nor is it put into an array. It just prints it up. You should be able to take it from there.

#include <stdio.h>
#define SIZE 500

int main() {
  int i,j, k,count=0; 
  char line1[SIZE];
  double n=0.0L;
  FILE *fp;

  printf("\n\n\n");
  fp=fopen("0kim.txt","r");
  fgets(line1, sizeof(line1), fp);
  i=0;
  while((line1[i]) != 'M') { //print dateTime string
    putchar(line1[i]);
    ++i;
  }
  putchar(line1[i]);
  k=i;
  while(line1[i]) {  //remove all comma's
    if(line1[i]==',') {
      for(j=i;line1[j];j++) 
        line1[j]=line1[j+1];
    }
    ++i;
  }  
  i=k;
  while(line1[i]) {   //wax on get number, wax off ;)
    while(line1[++i]<'0' && line1[i]); 
    if(i==SIZE-1) break;
    sscanf(line1+i, "%lf", &n); 
    count++;
    printf("\n%3d) %9.2lf", count, n);
    while(line1[++i] != ' ' && line1[i]);
  }  
  fclose(fp);
  printf("\n\n\t\t\t     press enter when ready");

  (void) getchar(); 
  return 0;
}

Thank You ! I will run It !

Can You help me again ?
If I want to get any values from key boad, so I can use : scan(line1+i, "%lf", &n)

can I change n with (line1+i) ?
I try but it display : 1) 0.00

Ex : I only get values= "6,594.94" , so line1+(i-?) ?
Thank You !

help me ! it is error !

# include "stdio.h"
# define SIZE 500

int main() {
  int i,j, k,count=0; 
  char line1[SIZE];
  double n=0.0L;
  FILE *fp;

  printf("\n\n\n");
  fp=fopen("D://readfile/sample1.txt","r");
  fgets(line1, sizeof(line1), fp);
  i=0;
  while((line1[i]) != 'M') { //print dateTime string
    putchar(line1[i]);
    ++i;
  }

  putchar(line1[i]);
  k=i;
  while(line1[i]) {  //remove all comma's
    if(line1[i]==',') {
      for(j=i;line1[j];j++) 
        line1[j]=line1[j+1];
    }
    ++i;
  }
  // thay doan while ben duoi = swith case !
  i=k;
    double tmp[1000];
	int dem = 0;
  while(line1[i]) {   //wax on get number, wax off ;)
	while(line1[++i]<'0' && line1+i);
    if(i==SIZE-1) break;
	//char *binh_binh = line1 +i;
	sscanf(line1+i, "%lf", &n);  // xem ky doan nay
	sscanf(line1+i, "%lf", &tmp[dem]);// lay du lieu tai vi tri thu i
	dem++;
	count++;
	printf("\n%3d) %9.2lf", count, n);
    while(line1[++i] != ' ' && line1[i]);
  // can dung con tro lay gia tri tung bien ra
  } //ket thuc while 
  fclose(fp);
  printf("\n\n\t\t\t     press enter when ready\n");
 
  //int size = sizeof(line1);
 

  for( int VT = 0; VT < dem; VT++)
  {
	printf("%9.2lf",tmp[VT]);
	printf("\n");
  }

  // tui can lay gia ti thu 10
  printf("\n\n===========values 10: %9.2lf",tmp[9]);

  // gia tri 14
  printf("\n\n==========values 14: %9.2lf",tmp[14]);

  (void) getchar(); 
  return 0;
}

I don't understand what you're doing with the variable n?

You don't want all the numbers going into the array temp[]?

Thank you reply !
I only test values !
It's ok !

I don't understand what you're doing with the variable n?

You don't want all the numbers going into the array temp[]?

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.