Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include <stdio.h>
- void main() {
- FILE *fp;
- char str[200];
- char ch1,ch2='A';
- int num_of_char = 0;
- int num_of_word = 0;
- printf("Enter path:\n");
- gets(str); // tttrrr.txt
- fp = fopen(str,"r");
- if (fp == NULL){
- printf("Can't open file\n");
- exit(0);
- }
- while(!feof(fp)){
- num_of_char ++;
- ch1 = fgetc(fp);
- if((ch1== ' ' || ch1== '\n' || ch1== '\t')&& (ch2!= ' ' && ch2!= '\n' && ch2!= '\t')&& num_of_char>1)
- num_of_word ++;
- if(!feof(fp))
- ch2 = ch1;
- }
- fclose(fp);
- if (ch2!= ' ' && ch2!= '\n' && ch2!= '\t'&& num_of_char>1){ // עבור המלה האחרונה
- num_of_word++;
- }
- printf("num of characters: %d\n", num_of_char-1 );
- printf("num of words: %d\n", num_of_word );
- }
- */
- /* // 2
- #include <stdio.h>
- void main(){
- char str[200],ch;
- FILE *fp;
- int n0=0,n1=0,n2=0,n3=0,n4=0,n5=0,n6=0,n7=0,n8=0,n9=0;
- printf("Enter path:\n");
- gets(str); // tttrrr.txt
- fp = fopen(str,"r");
- if (fp == NULL){
- printf("Can't open file\n");
- exit(0);
- }
- while(!feof(fp)){
- ch = fgetc(fp);
- switch (ch){
- case '0':{ n0 ++; break;}
- case '1':{ n1 ++; break;}
- case '2':{ n2 ++; break;}
- case '3':{ n3 ++; break;}
- case '4':{ n4 ++; break;}
- case '5':{ n5 ++; break;}
- case '6':{ n6 ++; break;}
- case '7':{ n7 ++; break;}
- case '8':{ n8 ++; break;}
- case '9':{ n9 ++; break;}
- }
- }
- fclose(fp);
- printf("0: %d\n1: %d\n2: %d\n3: %d\n4: %d\n5: %d\n6: %d\n7: %d\n8: %d\n9: %d\n",n0,n1,n2,n3,n4,n5,n6,n7,n8,n9);
- }
- */
- #include <stdio.h>
- #include<string.h>
- struct Product{
- char Name[20];
- double Price;
- int Amount;
- };
- void main(){
- FILE *fp;
- char str[200],ch;
- char annoying;
- struct Product P;
- int count=0,amount1=0,sum=0;
- double price1=0,best_price = 0,price_of_all=0;
- char name[20],best_name[20];
- printf("Enter path:\n");
- gets(str); // tttrrr.txt
- /*
- fp = fopen(str,"w");
- do{
- printf("Enter Product Name: ");
- scanf("%s",P.Name);
- printf("Enter Price: ");
- scanf("%lf",&P.Price);
- printf("Enter Amount ");
- scanf("%d",&P.Amount);
- fprintf(fp,"%s\n%.2lf\n%d\n",P.Name,P.Price,P.Amount);
- printf("Enter 'y' to create a new product or 'n' to finish: ");
- flushall();
- annoying = getchar();
- while(annoying != 'n'&& annoying != 'N' && annoying != 'y' && annoying != 'Y'){
- printf("Please enter a legal input: ");
- flushall();
- annoying = getchar();
- }
- } while(annoying == 'y' || annoying == 'Y');
- fclose (fp);
- */
- /////// עד כאן קלטנו
- fp = fopen(str,"r"); // tttrrr.txt
- while (!feof(fp)) {
- fgets(name,19,fp);
- fscanf(fp,"%lf",& price1);
- if (feof(fp)) break; // למהההה
- amount1=0; // למהההההה
- fscanf(fp,"%d",& amount1);
- sum += amount1;
- price_of_all += (price1 * amount1);
- if (price1 >= best_price){
- best_price = price1;
- strcpy(best_name,name);
- }
- }
- printf("How many products: %d\n",sum);
- printf("Price of all: %.2lf\n",price_of_all);
- printf("The most expensive: %s\n",best_name);
- fclose (fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment