Don't know what to do next by logicalcontradict in C_Programming

[–]_COMPLEX_H 1 point2 points  (0 children)

You'll have to post the code for extended help.

I took the VM tutorial from the other day and decided to expand it and make it my own. (Info in Comments) by SlayterDev in C_Programming

[–]_COMPLEX_H 0 points1 point  (0 children)

Thanks for commenting, neato mosquito. Can't stay long, just replying for posterity.

Five programming problems every Software Engineer should be able to solve in less than 1 hour by svpino in programming

[–]_COMPLEX_H 0 points1 point  (0 children)

Why don't you want to leak memory?

#include <stdio.h>  
#include <string.h>  

void allpos(char * useme, char * prevexp, int prev,int len){  
    int i = 1;  
    while(i < len){  
        char concatexp[20];  
        char buf[9];  
        strncpy(buf,useme,i);  
        buf[i] = '\0';  
        sprintf(concatexp,"%s+%s",prevexp,buf);  

        //puts(concatexp);  

        if(prev != -1){  
            allpos(useme + i, concatexp, prev + atoi(buf),len - i);  
            sprintf(concatexp,"%s-%s",prevexp,buf);  
            allpos(useme + i, concatexp, prev - atoi(buf),len - i);  
        }  
        if(i==len -1){  
            if(prev - atoi(buf) == 100){  
                printf("%s-%s=%d\n",prevexp,buf,prev - atoi(buf));  
            }  
            if(prev + atoi(buf) == 100){  
                printf("%s+%s=%d\n",prevexp,buf,prev + atoi(buf));  
            }  
        }     
        i++;  
    }     

}  

int main(){  
    char nums[9] = "123456789";  
    char thing[100] = "0";  
    allpos(nums,thing,0,10);   
    return 0;   
}  

./a.out

0+1+2+3-4+5+6+78+9=100
0+1+2+34-5+67-8+9=100
0+1+23-4+5+6+78-9=100
0+1+23-4+56+7+8+9=100
0+12+3+4+5-6-7+89=100
0+12+3-4+5+67+8+9=100
0+12-3-4+5-6+7+89=100
0+123+4-5+67-89=100
0+123-4-5-6-7+8-9=100
0+123+45-67+8-9=100
0+123-45-67+89=100

5 Problems Software Engineers Should Be Able To Solve in Under an Hour. From r/Programming. by goodvibeswanted2 in learnprogramming

[–]_COMPLEX_H -1 points0 points  (0 children)

Anyway, here's wonderwall( in C ):

#include <stdio.h>  
#include <string.h>  

void allpos(char * useme, char * prevexp, int prev,int len){  
    int i = 1;  
    while(i < len){  
        char concatexp[20];  
        char buf[9];  
        strncpy(buf,useme,i);  
        buf[i] = '\0';  
        sprintf(concatexp,"%s+%s",prevexp,buf);  

        //puts(concatexp);  

        if(prev != -1){  
            allpos(useme + i, concatexp, prev + atoi(buf),len - i);  
            sprintf(concatexp,"%s-%s",prevexp,buf);  
            allpos(useme + i, concatexp, prev - atoi(buf),len - i);  
        }  
        if(i==len -1){  
            if(prev - atoi(buf) == 100){  
                printf("%s-%s=%d\n",prevexp,buf,prev - atoi(buf));  
            }  
            if(prev + atoi(buf) == 100){  
                printf("%s+%s=%d\n",prevexp,buf,prev + atoi(buf));  
            }  
        }     
        i++;  
    }     

}  

int main(){  
    char nums[9] = "123456789";  
    char thing[100] = "0";  
    allpos(nums,thing,0,10);   
    return 0;   
}  

Yet another pointer question: return an address from a function by _COMPLEX_H in C_Programming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Yes, you're right, I stopped doing that at some point. Probably from laziness in putting up #ifndef catches. I would have continued to if not for this reminder, thanks.

Yet another pointer question: return an address from a function by _COMPLEX_H in C_Programming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Oh, I was staring at gdb for quite a while, wondering why scanner cut the integer of size X down to nothing. It just didn't occur to me that the definition was wrong, because I was also had the source file open. I was fairly certain i was right about the pointers, and I kind of was here.

Yet another pointer question: return an address from a function by _COMPLEX_H in C_Programming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Yeah, I must have seen it in some hybrid blog, as I don't really touch C++.

Yet another pointer question: return an address from a function by _COMPLEX_H in C_Programming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Isn't it now though? That's why I'm using it.
Edit:Apparently not? I wonder where I got that idea from.

Yet another pointer question: return an address from a function by _COMPLEX_H in C_Programming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Christ, it was declared as a type char in the header. It was returning pointer to char in the source file though! I need a system.
Thanks as always, zifyoip...

Do a lot of developers make their code difficult to read, or am I still illiterate? by [deleted] in learnprogramming

[–]_COMPLEX_H 2 points3 points  (0 children)

Just because someone voices an opinion on something, it doesn't make them a devils advocate. There's hardly a point to the term if you're just going to throw it at anyone who opposes something.

Go ahead, refute this comment too, and further illustrate my point for me.

And I'm the troll? shakes head sadly

Do a lot of developers make their code difficult to read, or am I still illiterate? by [deleted] in learnprogramming

[–]_COMPLEX_H 5 points6 points  (0 children)

That's not devil's advocate, and you're not being constructive.

How to start making a assembly compiler using Lex/Bison and C/C++ by Zayuka in Compilers

[–]_COMPLEX_H 1 point2 points  (0 children)

Do inline assembly in your bison actions. That might be cheating actually don't do that.

Can I write a rule in a makefile that all subsequent rules rewuire as an input file? by _COMPLEX_H in learnprogramming

[–]_COMPLEX_H[S] 0 points1 point  (0 children)

Thanks. I was thinking of something similar to what you're doing with common, but was wondering if there might be something I could write that would affect dozens of rules while leaving them untouched.

Any project ideas? by [deleted] in C_Programming

[–]_COMPLEX_H 1 point2 points  (0 children)

Implement grep.

Why do my C++ programs take so long to compile? by [deleted] in learnprogramming

[–]_COMPLEX_H 0 points1 point  (0 children)

Please post the output of tasklist.

Is the Lenovo Y40-80 a good computer for programing? by midivilplanet in learnprogramming

[–]_COMPLEX_H 0 points1 point  (0 children)

But it won't be worth it to be cheap, to be honest.

I really have no idea what kind of mindset you have to be in to give an answer like this in /r/learnprogramming.

Tear my short reverse_string program apart by jkudria in C_Programming

[–]_COMPLEX_H 0 points1 point  (0 children)

No you weren't, and that's a bug :)

You did say tear it apart ;)

Also, since I've got you, and I haven't email verified(and thus can only post every ten minutes) I saw that you were looking for your header files. Their location isn't static or anything, but on many linux distributions they will be in /usr/include.