Sinisterly
My First C Program - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.li/Forum-C-C-Obj-C)
+--- Thread: My First C Program (/Thread-My-First-C-Program--61643)

Pages: 1 2


My First C Program - Eclipse - 06-30-2015

Code:
#include <stdio.h> #include <stdlib.h> void usage() { printf("Usage: ./postcalc.c current_post_count time posts_per_day\n"); } int main(int argc, char *argv[]) { if(argc > 4) { printf("Too many arguments.\n"); usage(); } else if(argc < 4) { printf("You have not passed enough arguments.\n"); usage(); } else if(argc == 4) { int current_post_count = atoi(argv[1]); int time = atoi(argv[2]); int posts_per_day = atoi(argv[3]); int result = posts_per_day * 30.436 * 12 * time; result = result + current_post_count; printf("In %d years, your post count will be %d.\n", time, result); } else { usage(); } return 0; }

Also, I wanted to ask whether or not the above program is vulnerable to a buffer overflow attack, and if so, why? (@Dyme? Since you're the pro at exploiting buffer overflows in TEXETs. Tongue)


RE: My First C Program - Reiko - 06-30-2015

No buffer overflows here.. perhaps an (unexploitable?) int overflow, though


RE: My First C Program - phyrrus9 - 06-30-2015

Tip: Use cURL to retrieve the member profile information so that the info is auto updating and doesnt require the user to go through and manually input it. Similar to this PHP script: https://infallible.io/usersig.php?uid=1 [Image: usersig.php?uid=1]


RE: My First C Program - roger_smith - 07-01-2015

(06-30-2015, 08:52 PM)phyrrus9 Wrote: Tip: Use cURL to retrieve the member profile information so that the info is auto updating and doesnt require the user to go through and manually input it. Similar to this PHP script: https://infallible.io/usersig.php?uid=1 [Image: usersig.php?uid=1]

I think this is just a basic calculator type program.


RE: My First C Program - Eclipse - 07-01-2015

(06-30-2015, 08:52 PM)phyrrus9 Wrote: Tip: Use cURL to retrieve the member profile information so that the info is auto updating and doesnt require the user to go through and manually input it. Similar to this PHP script: https://infallible.io/usersig.php?uid=1 [Image: usersig.php?uid=1]

(07-01-2015, 12:13 AM)roger_smith Wrote: I think this is just a basic calculator type program.

It's not a bad idea for some more practice. I'll attempt it sometime.


RE: My First C Program - 0xDEAD10CC - 07-01-2015

Why does error() return an int when it's not used?
Code:
int error() { printf("Usage: ./postcalc.c current_post_count time posts_per_day\n"); return 0; }

^^ Also, "error" is definitely not an appropriate name for a function which only prints out the usage command line to stdout. Just name it usage().
Code:
void usage(void) { /* print out message to stdout (or stderr) here */ }



RE: My First C Program - Eclipse - 07-02-2015

(07-01-2015, 10:20 PM)0xDEAD10CC Wrote: Why does error() return an int when it's not used?
Code:
int error() { printf("Usage: ./postcalc.c current_post_count time posts_per_day\n"); return 0; }

^^ Also, "error" is definitely not an appropriate name for a function which only prints out the usage command line to stdout. Just name it usage().
Code:
void usage(void) { /* print out message to stdout (or stderr) here */ }

I kinda just hacked that bit because I didn't want to write the same thing out multiple times. Thanks for the advice, it's always appreciated.

Yeah, error() should be void instead of int.


RE: My First C Program - tropic - 07-04-2015

(07-01-2015, 12:13 AM)roger_smith Wrote: I think this is just a basic calculator type program.

Lol this isn't a basic calculator type program (if it did, it would at least accept infix input and have at least 4 arithmetic operations), this is a testament to OP's autism and desire for attention. This code is so fucking pointless it hurts.


RE: My First C Program - blackhatcat - 07-04-2015

(07-04-2015, 09:19 AM)tropic Wrote: Lol this isn't a basic calculator type program (if it did, it would at least accept infix input and have at least 4 arithmetic operations), this is a testament to OP's autism and desire for attention. This code is so fucking pointless it hurts.

Looks like OP has just hit ex12 on learncodethehardway about if and else statements and for some reason thought it's worth showing off almost identical code as given in the example on the site.

My advice is to focus on learning and share your code when you have something worth sharing.


RE: My First C Program - Eclipse - 07-04-2015

(07-04-2015, 02:10 PM)blackhatcat Wrote: Looks like OP has just hit ex12 on learncodethehardway about if and else statements and for some reason thought it's worth showing off almost identical code as given in the example on the site.

My advice is to focus on learning and share your code when you have something worth sharing.

I did 5 of the exercises and did the rest of it from google. This isn't a program intended for actual use, rather just a testament to the fact that I'm learning C. This thread serves no purpose other than to get feedback and improve.

We all know you guys are leet and have been since you came out of your mum's cunt, but we're not all so gifted.