Good day! Can I ask how to convert a string to int in turbo C. For example:
void comp()
{
FILE *fp;
int i,x;
long int deci;
char bin[8];
char *str=0;
char buf[1024];
fp=fopen("C:\enc.txt","w");
printf("Enter a text: ");
scanf("%[^\n]",str);
init(str);
for(i=0;i<128;i++)
{
if(code[i])
{
printf("'%c': %s\n",i, code[i]);
}
}
I'm making a binary code here with the use of string.
encode(str, buf);
deci=decimal(buf);
printf("%li", deci);
fprintf(fp,"%s",deci);
fclose(fp);
}
Here is the function decimal()
int decimal(long int decimal)
{
int dc, power;
power=1;
ht=0;
while(decimal>0)
{
dc+=decimal%10*power;
decimal=decimal/10;
power=power*2;
}
return dc;
}
Thanks for the responses!
I'll assume you are reading a stream of integers as string, and want them to be converted into integers.
Create a new integer array. Run a loop and convert each character into an integer.
And here you have, all the integer data stored into an integer array.
EDIT:
If you want to store the string into an integer,