cv5
This commit is contained in:
		
							parent
							
								
									4bfd81f296
								
							
						
					
					
						commit
						6cd148ed06
					
				@ -2,6 +2,7 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#define SIZE 100
 | 
			
		||||
#define MY_ERROR_OUTPUT stderr // chybovy vystup
 | 
			
		||||
 | 
			
		||||
@ -24,13 +25,13 @@ int compare_students(const void *a, const void *b) {
 | 
			
		||||
	return strcmp(student_a->name, student_b->name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int check_and_parse_line(char *line, int *votes, char *name) {
 | 
			
		||||
int check_line(char *line, int *votes, char *name) {
 | 
			
		||||
   
 | 
			
		||||
   // najdenie prvej medzery v retazci
 | 
			
		||||
    char *space_pos = strchr(line, ' ');
 | 
			
		||||
    char *space = strchr(line, ' ');
 | 
			
		||||
    
 | 
			
		||||
    // kontrola, ci sa nasla medzera
 | 
			
		||||
    if (space_pos == NULL) {
 | 
			
		||||
    if (space == NULL) {
 | 
			
		||||
        return 0; // neplatny riadok
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
@ -40,9 +41,13 @@ int check_and_parse_line(char *line, int *votes, char *name) {
 | 
			
		||||
    if (*votes == 0) {
 | 
			
		||||
        return 0; // premena sa nepodarila
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	//preskocenie inych znakov na zaciatku nez cislo
 | 
			
		||||
	while (*end != '\0' && !isdigit(*end)) {
 | 
			
		||||
		end++; //posuvam sa na dalsi znak v retazci
 | 
			
		||||
	}
 | 
			
		||||
    // nastavenie ukazovatela name na miesto za prvou medzerou
 | 
			
		||||
    char *name_start = space_pos + 1;
 | 
			
		||||
    char *name_start = space + 1;
 | 
			
		||||
 | 
			
		||||
    // nacitanie mena
 | 
			
		||||
    memset(name, 0, SIZE); // vynulovanie pomocneho pola pre meno
 | 
			
		||||
@ -88,7 +93,7 @@ int main() {
 | 
			
		||||
		break;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (check_and_parse_line(line, &votes, name) == 0) {
 | 
			
		||||
		if (check_line(line, &votes, name) == 0) {
 | 
			
		||||
            printf("Neplatny format");
 | 
			
		||||
            continue; // preskoci riadok a nacita dalsi
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								cv5/program.exe
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								cv5/program.exe
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user