Hello, I have this program that reads and prints the csv file, which is a list of students that goes in this format name, surname, ticket, age, email and prints the list like this:
name,surname,ballot,age,email
name,surname,ballot,age,email
name,surname,ballot,age,email
what I want is to print them like this without commas and with a jump
name surnames age ticket email
name surnames age ticket email
name surnames age ticket email
this is the code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//1) Funcion Recuperar
void furec(){
char opbackin[100]={};
FILE*lista_alumnos;
lista_alumnos=fopen("lista_alumnos.csv","r");
system("cls"); //Windows
//system("clear"); //Linux
printf("Recuperar lista de alumnos del 1CV2\n\n");
if(lista_alumnos==NULL)
{
printf("Error al abrir el fichero\n");
}
else
{
while(!feof(lista_alumnos))
printf("%c",getc(lista_alumnos));
}
printf("\n\nMenu:\n\n1) regresar | 2) Salir (Presionar cualquier tecla)\n\n");
printf("Terminal> ");
scanf("%s",&opbackin);
//Regresa al programa inicial '1' o 'recuperar'
if(strcmp(opbackin,"regresar")==0) {
main();
}
else {
if(strcmp(opbackin,"1")==0) {
main();
}
}
return;
}
//Programa principal
int main(void) {
char opin[100]={};
system("cls"); //Windows
//system("clear"); //Linux
//Textos de inicio
printf("Lista de alumnos del grupo 1CV2\n\nIngresa una opcion (numero o texto):\n\n1) recuperar\n\n");
printf("Terminal> ");
scanf("%s",&opin);
//Recupera informacion de alumno ingresando '1' o 'recuperar'
if(strcmp(opin,"recuperar")==0) {
furec();
}
else {
if(strcmp(opin,"1")==0) {
furec();
}
}
return 0;
}
As you can see it only reads the file, I don't know how to do it at least to remove the commas :/
You just have to confirm that the current character is a comma or a line break, in the following:
You could change it to:
And that's it :), I've made some modifications to your code, I hope you feel comfortable with them.
Here the complete code:
With the test example that you put in the question, it gives me the following result: