alguien me ayuda con este codigo? en la parte de int esNumero estoy mal
Publicado por ismael (1 intervención) el 27/03/2022 06:56:52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N_MATERIAS 5
#define N_ALUMNOS 5
typedef struct _Alumno{
char Nombre[40];
float Notas[N_MATERIAS];
float Promedio;
}ALUMNO;
char Materias[N_MATERIAS][40];
int RegistrarEstudiantes(ALUMNO a[]);
int RegistrarClases();
int main (){
ALUMNO Estudiante[N_ALUMNOS];
RegistrarClases();
RegistrarEstudiantes(Estudiante);
int i = 0;
while(i < N_MATERIAS){
printf("Nombre : %s\n",Materias[i]);
i++;
}
return 0;
}
int RegistrarClases(){
int i = 0;
int Result = 0;
printf("\t\tREGISTRE MATERIAS\n");
while(i < N_MATERIAS){
printf("MATERIA (%d) : ", (i+1)); fflush(stdin);
Result = scanf("%[^\n]",Materias[i]);
if((Result == EOF) || (ferror(stdin))){
return 0;
}
i++;
}
return 1;
}
int RegistrarEstudiantes(ALUMNO a[]){
int i = 0 , j;
int Result = 0;
char buffer[30];
float suma;
while(i < N_ALUMNOS){
system("cls");
printf("\t\tREGISTRO DE ESTUDIANTES\n\n");
printf("NOMBRE Y APELLIDO : "); fflush(stdin);
Result = scanf("%[^\n]",a[i].Nombre);
if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
suma = 0;
printf("\t\tREGISTRE NOTAS:\n");
for(j = 0; j < N_MATERIAS; j++){
do{
do{
printf("%s : ",Materias[j]); fflush(stdin);
Result = scanf("%[^\n]",buffer);
if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
}while(!esNumero(buffer));
errno = 0;
a[i].Notas[j] = (float)strtod(buffer,NULL);
if(error != 0){
return 0;
}
}while( (a[i].Notas[j] > 10) || (a[i].Notas[j] < 0));
suma += a[i].Notas[j];
}
a[i].Promedio = suma/N_MATERIAS;
i++;
}
return 1;
}
int esNumero(const char* buffer){
if((buffer == NULL) || (buffer[0] == '\0') || (strcmp(buffer,"-") == 0) || (strcmp(buffer,"-") == 0 ){
return 0;
}
int i = 0,nPuntos = 0;
while(buffer[i] != '\0'){
if(buffer[i] == '.'){
if(++nPuntos > 1){
return 0;
}
}
if( !(isdigit(buffer[i]) || buffer[i] == '.' || ((buffer[i] == '-') && (i = 0) ) ) ){
return 0;
}
i++;
}
return 1;
}
#include <stdlib.h>
#include <string.h>
#define N_MATERIAS 5
#define N_ALUMNOS 5
typedef struct _Alumno{
char Nombre[40];
float Notas[N_MATERIAS];
float Promedio;
}ALUMNO;
char Materias[N_MATERIAS][40];
int RegistrarEstudiantes(ALUMNO a[]);
int RegistrarClases();
int main (){
ALUMNO Estudiante[N_ALUMNOS];
RegistrarClases();
RegistrarEstudiantes(Estudiante);
int i = 0;
while(i < N_MATERIAS){
printf("Nombre : %s\n",Materias[i]);
i++;
}
return 0;
}
int RegistrarClases(){
int i = 0;
int Result = 0;
printf("\t\tREGISTRE MATERIAS\n");
while(i < N_MATERIAS){
printf("MATERIA (%d) : ", (i+1)); fflush(stdin);
Result = scanf("%[^\n]",Materias[i]);
if((Result == EOF) || (ferror(stdin))){
return 0;
}
i++;
}
return 1;
}
int RegistrarEstudiantes(ALUMNO a[]){
int i = 0 , j;
int Result = 0;
char buffer[30];
float suma;
while(i < N_ALUMNOS){
system("cls");
printf("\t\tREGISTRO DE ESTUDIANTES\n\n");
printf("NOMBRE Y APELLIDO : "); fflush(stdin);
Result = scanf("%[^\n]",a[i].Nombre);
if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
suma = 0;
printf("\t\tREGISTRE NOTAS:\n");
for(j = 0; j < N_MATERIAS; j++){
do{
do{
printf("%s : ",Materias[j]); fflush(stdin);
Result = scanf("%[^\n]",buffer);
if( (Result == EOF) || (ferror(stdin)) ){
return 0;
}
}while(!esNumero(buffer));
errno = 0;
a[i].Notas[j] = (float)strtod(buffer,NULL);
if(error != 0){
return 0;
}
}while( (a[i].Notas[j] > 10) || (a[i].Notas[j] < 0));
suma += a[i].Notas[j];
}
a[i].Promedio = suma/N_MATERIAS;
i++;
}
return 1;
}
int esNumero(const char* buffer){
if((buffer == NULL) || (buffer[0] == '\0') || (strcmp(buffer,"-") == 0) || (strcmp(buffer,"-") == 0 ){
return 0;
}
int i = 0,nPuntos = 0;
while(buffer[i] != '\0'){
if(buffer[i] == '.'){
if(++nPuntos > 1){
return 0;
}
}
if( !(isdigit(buffer[i]) || buffer[i] == '.' || ((buffer[i] == '-') && (i = 0) ) ) ){
return 0;
}
i++;
}
return 1;
}
Valora esta pregunta


0