עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

לא מצליח לקמפל - שפת C

Featured Replies

  • תגובות 47
  • צפיות 4.4k
  • נוצר
  • תגובה אחרונה
פורסם
  • מחבר

טוב סוף סוף סיימתי את העבודה, תודה לכולם, לשניצל ו Gil28 על התמיכה! :xyxthumbs::yelclap:

הנה הקוד סתם למי שמועניין או שבעתיד נתקל בזה:



#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>


int numberToLettersFile(int num,FILE *out);
int numberToLetters(int num);

/* Program that change the numbers to word in range of 0-99. */
/* The user has 3 optios: */
/* Option one: enter numbers manually as a standard input and get the words as a standard output by running the program: ./numbers */
/* Option two: get numbers from file and get the word as a standard output by running the program: ./numbers in.txt */
/* Option tree: get numbers from input file and get the output on other file by running the program: ./numbers in.txt out.txt */


int main(int argc, char* argv[])
{
FILE *inputf, *outputf;
int i=0,num=0;
char line[100]={0};
char *temp;
int numbers[100]={0};
int counter;




if(argc > 3) /* more then 2 names */
{
fprintf(stderr,"Eror! You cant enter more then 2 names.\n Goodbye!\n");
exit(0);
}




if(argc==1) /* no names - regular input and output */


{
printf("please enter numbers between 0-99:\n");
gets(line); /* put the number in a string named 'line' */
temp = strtok(line," "); /* sparte the numbers and put them in the arry named 'numbers' */
while(temp!=NULL)
{
num=atoi(temp);
numbers[i]=num;
i++;
counter++;
temp = strtok(NULL," ");
}
for(i=0;i<counter-1;i++) /* send the numbers to the func numberToLetters the get them as a word */
numberToLetters(numbers[i]);


printf("\nCommand successfull!\nGood Bye!\n\n");
}


if(argc==2) /* if one name - input from file and a regular output */
{
if(!(inputf=fopen(argv[1],"r")))
{
perror("Cannot open input file\n");
exit(0);
}


while(!feof(inputf)) /* put all the numbers from the input file to the arry */
{
fscanf(inputf,"%d",&numbers[i]);
i++;
counter++;
}


for(i=0;i<counter-2;i++) /* send the numbers to the func numberToLetters the get them as a word */
numberToLetters(numbers[i]);

printf("\nCommand successfull!\nGood Bye!\n\n");
fclose(inputf);
}


if(argc==3) /* if two names - get the numbers from file and put the word in another file */
{
if(!(inputf=fopen(argv[1],"r")))
{
perror("Cannot open input file file\n");
exit(0);
}


if(!(outputf=fopen(argv[2],"wt")))
{
perror("Cannot open output file\n");
exit(0);
}


while(!feof(inputf)) /* put all the numbers from the input file to the arry */
{
fscanf(inputf,"%d",&numbers[i]);
i++;
counter++;
}


for(i=0;i<counter-1;i++) /* send the numbers to the func numberToLettersFile the get them as a words inside the file*/
numberToLettersFile(numbers[i],outputf);

printf("\nCommand successfull!\nGood Bye!\n\n");
fclose(inputf);
fclose(outputf);

}


return 0;
}


int numberToLettersFile(int num,FILE *out) /* get the numbers and put them inside an output file as a words */
{


int ahadot,asarot;
char firstWord[11][6]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
char tenPlus[10][10]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
char secondWord[10][8]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};






if(num>=0 && num<=10) /* if number between 0-10 */
{
fprintf(out,"%s \n",firstWord[num]);
}


if(num>10 && num<20) /* if number between 11-19 */
{
fprintf(out,"%s \n",tenPlus[(num%10)-1]);
}


if(num>19 && num<100) /* if number between 20-99 */
{
ahadot=num%10;
asarot=num/10;


if(ahadot==0)
fprintf(out,"%s \n",secondWord[asarot-2]);


else
fprintf(out,"%s %s\n",secondWord[asarot-2],firstWord[ahadot]);


}
return 0;
}


int numberToLetters(int num)
{
int ahadot,asarot;
char firstWord[11][6]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
char tenPlus[10][10]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
char secondWord[10][8]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};




if(num>=0 && num<=10) /* if number between 0-10 */
{
printf("%s \n",firstWord[num]);
}


if(num>10 && num<20) /* if number between 11-19 */
{
printf("%s \n",tenPlus[(num%10)-1]);
}


if(num>19 && num<100) /* if number between 20-99 */
{
ahadot=num%10;
asarot=num/10;


if(ahadot==0)
printf("%s \n",secondWord[asarot-2]);


else
printf("%s %s\n",secondWord[asarot-2],firstWord[ahadot]);
}
return 0;
}

פורסם

יש לך שכפול קוד מטורף - numberToLetters ו-numberToLettersFile זהות לחלוטין למעט הקובץ אליהן הן מדפיסות. תחשוב איך לטפל בזה.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.