Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<ctype.h>
- #define _CRT_SECURE_NO_WARNINGS_
- #include <string.h>
- void antigorner(char*, int, int);
- int gorner(char*, int);
- void SetError(int errors[][10], int firstBase);
- int main()
- {
- int errors[2][10] = { { 2, 3, 4, 8, 9, 10, 16, 20, 25, 30 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
- FILE* f;
- f = fopen("my.txt", "r");
- int resG, firstNum, firstBase, secondBase;
- char firstSym[10];
- char res[10];
- char bigStr[300];
- char allNumber[300];
- while (fscanf(f, "%s (%d) = %s;",&firstNum, &firstBase, allNumber) != EOF)
- {
- char *pch = strtok(allNumber, ",");
- printf("%d (%d) = ", firstNum, firstBase);
- while (pch != NULL)
- {
- sscanf(pch, "%s(%d)", firstSym, &secondBase); // не верно
- resG = gorner(firstSym, secondBase);
- if (resG != firstNum)
- {
- antigorner(res, firstNum, secondBase);
- SetError(errors, firstBase);
- printf("%s (%d), ", res, secondBase);
- }
- pch = strtok(NULL, ",");
- }
- }
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- printf("%d\t", errors[i][j]);
- }
- printf("\n");
- }
- system("pause");
- return 0;
- }
- void antigorner(char* res, int num, int base)
- {
- int tmp = 0;
- int n = num;
- int numberofdigits = 0;
- while (n)
- {
- n = n / base;
- numberofdigits++;
- }
- char* pres = res;
- while (numberofdigits--)
- {
- *pres = 0;
- pres++;
- }
- *pres = 0;
- while (num)
- {
- *--pres = ((tmp = num % base) < 10) ? (tmp + '0') : (tmp + 'A' - 10);
- num = num / base;
- }
- }
- int gorner(char* s, int base)
- {
- int res = 0;
- while (*s)
- {
- res = res * base;
- if (isdigit(*s))
- {
- res = res + *s - '0';
- s++;
- }
- else
- {
- res = res + toupper(*s) - 'A' + 10;
- s++;
- }
- }
- return res;
- }
- void SetError(int errors[][10], int firstBase)
- {
- int i;
- for (i = 0; i <= 10; i++)
- {
- if (errors[0][i] == firstBase)
- {
- break;
- }
- }
- errors[1][i] += 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement