hi, i have been unable to solve a problem related to C (i'am a newbie girl). I've googled around and maybe I have a flat learning curve :-(
the fact is that i need to write a program that reads from a .txt file and print the output to another .html file (table)
the input file has 6 space-separated fields per line (activity_code, activity, begining_date, ending_date, days and hour of the day -Morning/Afternoo/Night) and downwards is alike.
i.e. this 2 lines:
ZZZ Tancat 01/01/2009 31/12/2009 SMT MN

PER PerlMeeting 01/05/2009 31/05/2009 TWF N

How do I split this strings and assign them to a structure in order to can handle data? Here is the code I wrote, it's very simple and hope you can help me with some advice. Thanks in advance.

#include <stdio.h>
#include <ctype.h> /* to handle isspace()         
#define MAXFILES 200
#define MAXLEN 50

typedef struct {
       char *CODE[MAXLEN];
       char *NAME[MAXLEN];
       char *DATE_IN[MAXLEN];
       char *DATE_OUT[MAXLEN];
       char *DoW[MAXLEN];
       char *HOUR[MAXLEN];
} rec_s;
int main() 
{
  rec_s LOG[MAXLEN];
  char c[120];  /* declare a char array */
  char actividad[MAXLEN];
  char d;
  char words[MAXLEN];
  char delims[] = " ";
  
  int count=0;
  char *buffer;
  int i;
  int j;
  
  FILE *file;  /* declare a FILE pointer  */
  
  file = fopen("requests.txt", "r"); 
  
 
  /* open a text file for reading */

  if(file==NULL) {
    printf("Error: can't open file.\n");
    
    return 1;
  }
  else {
    printf("File opened!:\n\n");
    
   
   
    while(!feof(file)) {
    d = fgetc(file);
        if ( ! isspace (d) ) /* how do i use this function to assign every line string (6) to its appropriate field? */
        {
        fgets(c, 120, file); 
        puts(c);        /* this shows in screen the input file */
                        /* I don't know how to add every string to the structure */
        }
        

     
       }
   printf("\n\nNow closing file...\n");
    fclose(file);
    return 0;
     
  }    
    
}

Whoops my bad...Please disregard the following

hope you can help me with some advice.

First, you must understand what constitutes a string in C. It is a sequence of chars terminated with a '\0'.
So if I have this:

char fullname[] = "Jiminy Cricket";

and I want to split it into name and last name, I have to make it as: 'J', 'i', 'm', 'i', 'n', 'y', '\0'; and 'C', 'r', 'i', 'c', 'k', 'e', 't', '\0'; Secondly, there's not memory to hold any string in your structure rec_s, only pointers that will hold the address of something.

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.