Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Roli ( 13 years ago )
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#define MIN_DB 2
#define MAX_DB 15
#define MAX_KAR 5
int getline(char s[], int lim) {
int i;
char c;
for(i=0;i<lim && (c=getchar())!='\n' && c!=EOF;++i)s[i]=c;
s[i]='\0';
while(c!='\n'&& c!=EOF)c=getchar();
return i;
}
int egesz(char s[]){
int i;
i=(s[0]=='-' || s[0]=='+')?1:0;
while(s[i]){
if(!isdigit(s[i]))return 0;
i++;
}
return 1;
}
int lebeg(char s[]){
int i=0, kezd;
while(isspace(s[i])) ++i;
if(s[i]=='+'||s[i]=='-') ++i;
kezd=i;
while(isdigit(s[i])) ++i;
if(s[i]=='.') ++i;
while(isdigit(s[i])) ++i;
if(i==kezd||kezd+1==i&&s[kezd]=='.') return 0;
if(toupper(s[i])=='E'){
++i;
if(s[i]=='+'||s[i]=='-')++i;
if(!isdigit(s[i])) return 0;
while(isdigit(s[i])) ++i;}
if(isspace(s[i])||!s[i]) return 1;
else return 0;
}
struct adatok {
int ertek;
double watt;
int tures;
};
void main(void) {
char tmp[MAX_KAR+2];
struct adatok ellenalas[MAX_DB];
int i=0, db=0, ok=0, vege=0, jo=0, rossz=0;
printf("Ellenalasok nyilvantartasat vegzo program!\n");
printf("------------------------------------------\n\n");
do {
ok=0;
do {
printf("Kerem adja meg a %d. ellenalas erteket!\n",db+1);
if(!getline(tmp,MAX_KAR+1)) {
if(db<MIN_DB) {
printf("Minimum %d ellenalast meg kell adnia!\n\n", MIN_DB);
}else{
printf("Ures sort utott, a bekeresnek vege!\n\n");
ok=1;
vege=1;
}
}else{
if(strlen(tmp) > MAX_KAR) {
printf("Tul sok karaktert adott meg!\n\n");
}else{
if(!egesz(tmp)) {
printf("Nem egesz szamot adott meg!\n\n");
rossz=1;
}else{
ellenalas[db].ertek = atoi(tmp);
if( ellenalas[db].ertek < 0 ) {
printf("Nem adhat meg negativ erteket!\n\n");
}else{
ok=1;
jo=1;
}
}
}
}
}while(!ok);
if(!vege) {
ok=0;
do {
printf("Kerem adja meg a Watt-ot!\n\n");
if(!getline(tmp,MAX_KAR+1)) {
printf("Nem adhat meg ures sort!\n\n");
}else{
if(strlen(tmp) > MAX_KAR) {
printf("Tul sok karaktert adott meg!\n\n");
}else{
if(!lebeg(tmp)) {
printf("Nem lebegopontos szamot adott meg!\n\n");
rossz=1;
}else{
ellenalas[db].watt = atof(tmp);
if( ellenalas[db].watt < 0 ) {
printf("Nem adhat meg negativ erteket!\n\n");
}else{
ok=1;
}
}
}
}
}while(!ok);
ok=0;
do {
printf("Kerem adja meg a Turest!\n\n");
if(!getline(tmp,MAX_KAR+1)) {
printf("Nem adhat meg ures sort!\n\n");
}else{
if(strlen(tmp) > MAX_KAR) {
printf("Tul sok karaktert adott meg!\n\n");
}else{
if(!egesz(tmp)) {
printf("Nem egesz szamot adott meg!\n\n");
rossz=1;
}else{
ellenalas[db].tures = atoi(tmp);
if(ellenalas[db].tures < 0 || ellenalas[db].tures > 100) {
printf("Az erteknek 0 es 100 koze kell esnie!\n\n");
}else{
ok=1;
jo=1;
}
}
}
}
}while(!ok);
++db;
}
if(db == MAX_DB) {
printf("Elertuk a max beviheto ellenalast!\n\n");
vege=1;
}
}while(!vege);
if(vege) {
if(!rossz) {
printf("A bevitt adatok a kovetkezok:\n\n");
printf("Sorszam\t\tErtek(Ohm)\tWatt\t\tTures(%)\n\n");
for(i=0;i<db;++i) {
printf("%d\t\t%d\t\t%.2f\t\t%d\n",i+1, ellenalas[i].ertek, ellenalas[i].watt, ellenalas[i].tures);
}
}
}
}
Revise this Paste