Untitled
unknown
plain_text
3 years ago
1.7 kB
5
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 500
typedef struct {
char name[20];
int puntuacion;
char location[20];
}Jugador;
// Marta|10-Barcelona#Juan|20-Madrid#Pedro|30-Sevilla
int myAtoi(char input[MAX]) {
int result = 0;
int i = 0;
//23\0 -> 50 y un 51
//0 -> 48
while(input[i] != '\0') {
//printf("\nValor de %c en ascii: %d\n", input[i], input[i]);
result = result * 10 + (input[i] - '0');
//printf("\n%d\n", result);
i++;
}
return result;
}
int main() {
Jugador player[10];
char input[500];
char aux[50];
int max = 0;
printf("Enter information: ");
fgets(input, MAX, stdin);
//printf("Longitud sin quitan: %d", (int)strlen(input));
input[strlen(input)-1] = '\0';
//printf("\nLongitud quitando: %d", (int)strlen(input));
//printf("\n%s\n", input);
int i = 0, j = 0;
while(input[i] != '\0') {
while(input[i] != '|') {
player[max].name[j] = input[i];
i++;
j++;
}
player[max].name[j] = '\0';
j = 0;
i++;
while(input[i] != '-') {
aux[j] = input[i];
j++;
i++;
}
aux[j] = '\0';
player[max].puntuacion = myAtoi(aux);
j = 0;
i++;
while(input[i] != '#' && input[i] != '\0') {
player[max].location[j] = input[i];
j++;
i++;
}
player[max].location[j] = '\0';
if(input[i] != '\0') {
i++;
max++;
}
}
printf("%s", player[0].name);
return 0;
}Editor is loading...