Skip to content
Snippets Groups Projects
Select Git revision
  • f156510134c0c2df1b012b4a1ea676524d78ee1d
  • main default
2 results

TripController.js

Blame
  • main.c 999 B
    #include "alloc.h"
    
    #include <string.h>
    #include <stdio.h>
    
    
    extern int fit_type;
    
    int main(int argc,char* argv[])
    {
    	char buf[1024];
    	char* tok;
    	int line_num; // 1,2,3,4,5
    	int fit_type=0;
    
    	if(argc!=2)
    	{
    		printf("!!!!!Usage: ./main input.txt\n");
    		return 0;
    	}
    
    	FILE* fp = fopen(argv[1],"r");
    
    	fgets(buf,sizeof(buf),fp);
    	tok = strtok(buf, " ");
    
    	line_num = atoi(tok);
    	if(line_num==0)
    	{
    		printf("line number is zero\n");
    		return 0;
    	}
    
    	tok = strtok(NULL, " ");
    	if(tok[0]=='F')
    		fit_type = 1;
    	else if(tok[0]=='B')
    		fit_type = 2;
    	else if(tok[0]=='W')
    		fit_type = 3;
    	else
    	{
    		printf("fit type is not correct\n");
    		return 0;
    	}
    
    	char** lines = (char**)m_malloc(line_num * sizeof(char*));
    
    	for(int i=0;i<line_num;i++)
    	{
    		memset(buf,0,sizeof(buf));
    		fgets(buf,sizeof(buf),fp);
    		buf[strlen(buf)-1]=0;
    
    		if(buf[0]=='s')
    		{
    			lines[i] = (char*)m_malloc(sizeof(char)*strlen(buf+2)+1);
    			strcpy(lines[i], buf+2);
    			printf("%s\n", lines[i]);
    			continue;
    		}
    	}
    	
    	return 0;
    
    }