mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
gets not a C11 standard, superceded by fgets
This commit is contained in:
parent
1b826807ed
commit
1d8d07efc9
@ -4,24 +4,25 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
char hex[17];
|
||||
#define MAX_STR_LEN 17
|
||||
char hex[MAX_STR_LEN];
|
||||
long long octal, bin, place;
|
||||
int i = 0, rem, val;
|
||||
|
||||
/* Input hexadecimal number from user */
|
||||
printf("Enter any hexadecimal number: ");
|
||||
gets(hex);
|
||||
fgets(hex, MAX_STR_LEN, stdin);
|
||||
|
||||
octal = 0ll;
|
||||
bin = 0ll;
|
||||
place = 0ll;
|
||||
|
||||
/* Hexadecimal to binary conversion */
|
||||
for(i=0; hex[i]!='\0'; i++)
|
||||
for (i = 0; hex[i] != '\0'; i++)
|
||||
{
|
||||
bin = bin * place;
|
||||
|
||||
switch(hex[i])
|
||||
switch (hex[i])
|
||||
{
|
||||
case '0':
|
||||
bin += 0;
|
||||
@ -87,11 +88,11 @@ int main()
|
||||
place = 1;
|
||||
|
||||
/* Binary to octal conversion */
|
||||
while(bin > 0)
|
||||
while (bin > 0)
|
||||
{
|
||||
rem = bin % 1000;
|
||||
|
||||
switch(rem)
|
||||
switch (rem)
|
||||
{
|
||||
case 0:
|
||||
val = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user