Skip to content

Instantly share code, notes, and snippets.

@ernado
Created October 5, 2013 00:49
Show Gist options
  • Save ernado/6835145 to your computer and use it in GitHub Desktop.
Save ernado/6835145 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define One 1
#define N 10 //number of elem in array "in"
#define Error_Of_Input -1 //if puted simbol wasn't NULL or 1
#define Error_in_ToInteger -2 //if puted simbol wasn't NULL or 1
size_t Pow10(size_t a, size_t n)
{
for(size_t i=0; i<n; i++)
a=a*10;
return a;
}
size_t toInteger(size_t* first, size_t size, size_t* _return)
{
if(first==NULL || size==(size_t)NULL)
return (size_t)NULL;
*_return=(size_t)NULL;
for(size_t i=0; i<size; i++)
{
if(first[i] !=(size_t)NULL && first[i]!=1)
{
return (size_t)NULL;
}
*_return+=Pow10(first[i],i);
}
return 1;
}
size_t main(size_t argc, char *argv[])
{
char put1simb;
size_t* in=(size_t*)malloc(sizeof(size_t)*N);
int count=(size_t)NULL;
size_t* _return= (size_t*)malloc(sizeof(size_t));
printf("Having finished entering an array place '\\n'\n");
while(put1simb!='\n')
{
if(scanf("%c", &put1simb)!=1)
{
free(in);
free(_return);
return Error_Of_Input;
}
if(put1simb=='1')
{
in[count]=1;
count++;
continue;
}
if(put1simb=='0')
{
in[count]=(size_t)NULL;
count++;
continue;
}
if(put1simb!='\n')
{
free(in);
free(_return);
return Error_Of_Input;
}
}
if( toInteger(in,count,_return))
{
printf("%zu", *_return);
free(in);
free(_return);
return 0;
}
else {
free(in);
free(_return);
Error_in_ToInteger;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment