Thread: Need a sample program.

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    20

    Need a sample program.

    I would like it if some of you can post some sample C programs. I'm testing out some color-schemes. Keep in mind this isn't my homework so it doesn't exactly have to work. The longer the better.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    On the Cprogramming.com website, in the C forum, you can't find C programs?

    Quickly, take a moment for prayer. You'll need all the help you can get to pass your class.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    20
    Quote Originally Posted by Adak View Post
    On the Cprogramming.com website, in the C forum, you can't find C programs?

    Quickly, take a moment for prayer. You'll need all the help you can get to pass your class.
    Not looking for small pieces of code i'm talking about one with hundreds of lines and a lot of functions, memory allocation, etc. I'm still new to C so I not exactly sure what can show up in C, that's why I'm testing the colorshemes to find the perfect one. Some values show up differently and functions too.

    I'm also not taking a class I'm learning C for fun.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    54
    That's kind of a silly request, but here.

  5. #5
    Bit Fiddler
    Join Date
    Sep 2009
    Posts
    79
    Go to sourceforge.net and download the source of any C project there.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Stfw

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by zerokernel View Post
    Not looking for small pieces of code i'm talking about one with hundreds of lines and a lot of functions, memory allocation, etc. I'm still new to C so I not exactly sure what can show up in C, that's why I'm testing the colorshemes to find the perfect one. Some values show up differently and functions too.

    I'm also not taking a class I'm learning C for fun.
    Well, then here's lesson #1 ... C is not about the color schemes in your IDE's editor.

    Quit messing with what does not matter and grab yourself a couple of decent books and tutorials on C programming and get on with what does...

  8. #8
    Registered User
    Join Date
    Nov 2010
    Posts
    20
    Quote Originally Posted by CommonTater View Post
    Well, then here's lesson #1 ... C is not about the color schemes in your IDE's editor.

    Quit messing with what does not matter and grab yourself a couple of decent books and tutorials on C programming and get on with what does...
    Yeah I needed that, I have put off programming C for a while. Thanks.

  9. #9
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Here's some simple programs I've written.

    Code:
    /* coffee */
    #include <stdio.h>
    #include <stdlib.h>
    
    void total(int y) {
    	float x = (y * 2.99);
    	printf("Your total is $%0.2f.", x);
    	return;
    }
    
    int main(int argc, char *argv[]) {
    	int y;
    	if (!argv[1]) {
    		printf("How many cups of coffee would you like? ");
    		scanf("%d", &y);
    		total(y);
    		return 0;
    	}
    	y = (atoi(argv[1]));
    	total(y);
    	return 0;
    }
    Code:
    /* digit counter */
    #include <stdio.h>
    
    int digits(const char *p) {
    	int x;
    	for (x = 0; *p != '\0'; p++) {
    		if (*p == '0' || *p == '1' || *p == '2' ||
    		*p == '3' || *p == '4' || *p == '5' ||
    		*p == '6' || *p == '7' || *p == '8' || *p == '9') x++;
    	}
    	return x;
    }
    
    int main() {
    	int x;
    	char y[256];
    	printf("Enter a string: ");
    	fgets(y, sizeof(y), stdin);
    	x = digits(y);
    	printf("That string has %d digits.\n", x);
    	return 0;
    }
    Code:
    /* spaces counter */
    #include <stdio.h>
    
    int spaces(const char *p) {
    	int x;
    	for (x = 0; *p != '\0'; p++)
    		if (*p == ' ') x++;
    	return x;
    }
    
    int main() {
    	int x;
    	char y[256];
    	printf("Enter a string: ");
    	fgets(y, sizeof(y), stdin);
    	x = spaces(y);
    	printf("That string has %d spaces.\n", x);
    	return 0;
    }
    Code:
    /* file reader */
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
    	if (!argv[1]) {
    		printf("USAGE: %s [input]\n", argv[0]);
    		return 1;
    	}
    	int x;
    	for (x = 1; x < argc; x++) {
    		FILE *in = (fopen(argv[x], "r"));
    		int y;
    		if (in == NULL) return 2;
    		while ((y = fgetc(in)) != EOF) putchar(y);
    	}
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 11:13 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Help with sample tax program
    By DaMonsta in forum C Programming
    Replies: 1
    Last Post: 05-15-2003, 03:45 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM