Login Register






My First C Program filter_list
Author
Message
My First C Program #1
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)

Reply

RE: My First C Program #2
No buffer overflows here.. perhaps an (unexploitable?) int overflow, though
PGP
Sign: F202 79C9 76F7 40BB 54EC 494F 5DEF 1D70 14C1 C4CC
Encrypt: A5B3 1B21 55E1 80AF 4C6E DE83 467B 8EFC 3DEE 681C
Auth: CD55 E8A5 1A08 2933 8BA6 BC88 D81F 1943 739A 3C47

Reply

RE: My First C Program #3
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]

Reply

RE: My First C Program #4
(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.
---
Click here to get started with Linux!

If I helped you, please +rep me, apparently we've started over on Rep and I'd like to break 100 again...

Inori Wrote: got clickbaited by roger

Reply

RE: My First C Program #5
(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.

Reply

RE: My First C Program #6
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 */ }

Reply

RE: My First C Program #7
(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.

Reply

RE: My First C Program #8
(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.

Reply

RE: My First C Program #9
(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.
whoami

Reply

RE: My First C Program #10
(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.

[+] 2 users Like Eclipse's post
Reply