daily pastebin goal
32%
SHARE
TWEET

FALTA_TERMINAR

Shuabah Apr 16th, 2018 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* strtoke(char *str, const char *delim)
  6. {
  7.   static char *start = NULL; /* stores string str for consecutive calls */
  8.   char *token = NULL; /* found token */
  9.   /* assign new start in case */
  10.   if (str) start = str;
  11.   /* check whether text to parse left */
  12.   if (!start) return NULL;
  13.   /* remember current start as found token */
  14.   token = start;
  15.   /* find next occurrence of delim */
  16.   start = strpbrk(start, delim);
  17.   /* replace delim with terminator and move start to follower */
  18.   if (start) *start++ = '\0';
  19.   /* done */
  20.   return token;
  21. }
  22.  
  23. struct nodo{
  24.     char nome[100];
  25.     char ator[100];
  26.     struct nodo *next;
  27. };
  28.  
  29. void ins_ord(struct nodo **head, char *p){
  30.     struct nodo *temp, *ptnovo = (struct nodo *)malloc(sizeof(struct nodo));
  31.     ptnovo->nome = p;
  32.     ptnovo->next = NULL;
  33.     if(*head == NULL || (*head)->nome[0] >= p[0]){
  34.         ptnovo->next = *head;
  35.         *head = ptnovo;
  36.         return;
  37.     }
  38.     temp = *head;
  39.     while(temp->next != NULL && temp->next->nome[0] < p[0]){
  40.         temp = temp->next;
  41.     }
  42.     ptnovo->next =temp->next->next;
  43.     temp->next = ptnovo;
  44.     return;
  45. }
  46.  
  47. int main(){
  48.     struct nodo *head = NULL;
  49.     FILE *resumo;
  50.     char str[1000];
  51.     resumo = fopen("C:\\Users\\lmrmurua\\Downloads\\resumo.txt","rt");
  52.     if(resumo == NULL){
  53.         printf("ERRO");
  54.         return 0;
  55.     }
  56.     while(fgets(str, 1000, resumo)){
  57.         char * p= strtoke(str, ",");
  58.         ins_ord(&head, p);
  59.         while(p){
  60.             p = strtoke(NULL, ",");
  61.         }
  62.         printf("%s\n",p);
  63.     }
  64. }
RAW Paste Data
Top