The Text fileSolutionCode include include include include in

The Text file

Solution

Code:

#include <stdio.h>
#include<conio.h>
#include<cstring>
#include <stdlib.h>
#include<malloc.h>
enum service
{
   Police=0,hospital=1,fire=2
};
struct help
{
   int id;
   double x;
   double y;
   service s;
   char *name;
}h[40];
int main()
{
   FILE * f;
size_t len = 0;
size_t read;

f = fopen(\"inp.txt\", \"r\");
if (f == NULL)
exit(EXIT_FAILURE);

const size_t line_size = 300;
   char* line = (char *)malloc(line_size);
   fgets(line, line_size, f);
   int count=0;
   while (fgets(line, line_size, f) != NULL)
   {
       char * token;
      
       h[count].id = atoi(strtok (line, \" \"));
       double d;
       sscanf(strtok (NULL, \" \"), \"%lf\", &d);
       h[count].x=d;
       sscanf(strtok (NULL, \" \"), \"%lf\", &d);
       h[count].y=d;
       int k=atoi(strtok (NULL, \" \"));
       h[count].s=(enum service)k;
       h[count].name=(char *)malloc(10);
       h[count].name=strtok (NULL, \" \");

      
       count++;
      
   }
   fclose(f);
   for (int i=0;i<count;++i)
   {
       printf(\"id: %d\ \",h[i].id);
       printf(\"x: %lf\ \",h[i].x);
       printf(\"y: %lf\ \",h[i].y);
       printf(\"service: %d\ \",h[i].s);
       printf(\"name: %s\ \",h[i].name);
   }
      
   getch();
   return 0;
}

The Text fileSolutionCode: #include <stdio.h> #include<conio.h> #include<cstring> #include <stdlib.h> #include<malloc.h> enum serv
The Text fileSolutionCode: #include <stdio.h> #include<conio.h> #include<cstring> #include <stdlib.h> #include<malloc.h> enum serv

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site