Hey, I just have a quick question that I can't find online.
let's say you have
is there a way to delete those unimportant 0's so that you are left with 50? it keeps the important 0 marker but deletes the unimportant ones?Code:int a=00050;
Hey, I just have a quick question that I can't find online.
let's say you have
is there a way to delete those unimportant 0's so that you are left with 50? it keeps the important 0 marker but deletes the unimportant ones?Code:int a=00050;
Yep.
all thanks to my secret decoder ring.Code:int a=50;
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
hmm maybe i should be clearer
what will happen is there will be
a char* test that takes in a number, and then i atoi(test) it to become an int
then i %10, /10 so i can store it in a linked list, each separate digit
those 0s will get stored, but i dont want them to. so how do i get rid of those 0s
btw they will be stored backwards so i cant just delete every 0 until it reads the 5
it needs to be like, read the singles 0, then the tens 5, then somehow know to delete the rest of zeros, so im wondering if theres a way to just get rid of them
Once you convert the number to an int, the trailing 0's make no difference.
but it does
i am putting in 002 and when i print my int it prints out 2 but when i print out the linked list it comes out to 0->0->2
Post your code. I suspect you're creating your linked list according to the length of the char array instead of stopping when there are no more decimal digits to be represented in the int.
this is my function attempt but i know its wrong; btw the above function is indeed taking the number backwards; that's intendedCode:struct integer* convert_integer(char* stringInt) { //not really in my funct: : : char* stringInt=deleteZeros(stringInt); int test=atoi(&stringInt[0]); struct integer* list=createNode(test%10); int k; for(k=1;k<strlen(stringInt);k++) { test/=10; list=insertBack(list,(test%10)); } return list; }
Code:char* deleteZeros(char* stringInt) { char* solve; int k=strlen(stringInt); while(k>0) { if(stringInt[k]==0) { stringInt[k]==NULL; k--; } else { return stringInt; } } }
Yeah - that's your problem. You're working with the int based on how many characters are in the string. Perhaps a better solution would be to loop as long as test > 0.Code:for(k=1;k<strlen(stringInt);k++) {
ahh thank you, now my code is currently
the code works mostly, thanks for the advice but when i run 000250 and then i print the linked list it prints 0250; so i tried to get rid of the last 0 using the code encased by MARKER; heheh it must be horribly written code cuz it just doesnt stop running :P infinite looop...somehowCode:struct integer* convert_integer(char* stringInt) { int test=atoi(&stringInt[0]); struct integer* list=createNode(test%10); int k; //for(k=1;k<strlen(stringInt);k++) { while(test>0) { test/=10; list=insertBack(list,(test%10)); } //MARKER struct integer* current=list; while(current->next!=NULL) { current=current->next; } if(current->digit==0) free(current); //END MARKER return list; }
Try
or something like that.Code:while(test >= 10)
ahhh wow you are right; thanks for the helpp :P :P im trying to read through it but i dont quite get the logic behind that while parameter but i'll look over it again; thanks so much XDD now all i have left is the subtract method haha thank you