//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#define SIZE 1000
//int maxtextbuffer = sizeof(char)*250;
//#define SIZE sizeof(char)*250
#define SIZE 255

int coresdetected() {
	FILE* fp;
	int count = 0; 
	int coresdetected = 0;
	char buf[SIZE];
	if( ( fp = fopen( "/proc/stat", "r" ) ) == NULL ) {
		fprintf( stderr, "Error opening file.\n" );
		exit( 1 );
	}

        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
		if (buf[count] == 'c'){
			if (buf[count+1] == 'p'){
				if (buf[count+2] == 'u'){
					if (buf[count+3] == '0' || buf[count+3] == '1' || buf[count+3] == '2' || buf[count+3] == '3' || buf[count+3] == '4' || buf[count+3] == '5' || buf[count+3] == '6' || buf[count+3] == '7' || buf[count+3] == '8' || buf[count+3] == '9'){
						coresdetected++;
		}
			}
				}
					}
	}
	//printf( "NUMBER OF CORES: %d\n", coresdetected );

	fclose( fp );
	return (coresdetected);
}
