Thread: different things to do, where to start?

  1. #1
    Registered User
    Join Date
    Feb 2011

    Exclamation Round double value x to i signifcant decimal places

    I'm supposed to do all these functions but i'm not sure how to do the printing of k-th digit

    C Ch [Character Case Change ]
    Change character Ch to uppercase and print it out
    c Ch [Character Case Change]
    Change character Ch to lowercase and print it out
    P i k [Print k-th Digit ]
    Print out the k-th digit of integer i
    R x i [Round Reals ]
    Round double value x to i signi cant decimal places
    S x [Separate ]
    Separate out the sign, integer part and fractional
    part of double value x
    D i x [Partition Integer ]
    Given integers i and x, print out two integers j and k,
    where the sum of j and k equals i, and when you take x%
    of i and truncate it you get j

    they read from this file.

    + -3 4
    + -4 -71
    - -41 -7
    * 3 -5
    / 141 13
    / 14 -3
    c F
    C f
    P 2143 3
    R 3.1415 2
    R 3.1415 3
    R 0.01015678 6
    S -3.1415
    S 31.415
    D 9 40
    D 10 40
    D 90 90
    c F
    C f
    so far this is what i have
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define FILENAME "CommandProj2(1).dat"
    int main(void) {
    	char operate, char_change;
    	double i, j;
    	FILE *file_in;
    	file_in = fopen(FILENAME, "r");
    	if (file_in == NULL)
    		printf("Error opening input file. \n");
    	fscanf(file_in, "%c %c", &operate, &char_change);
    		if (operate == 'c')
    			printf("%c", toupper(char_change));
    		else if (operate == 'C')
    			printf("%c", tolower(char_change));
    		else if (operate == 'P')
    		else if (operate == "R")
    		else if (operate == "S")
    		else if (operate == "D")
    	return 0;
    Last edited by jackellyn; 04-25-2011 at 06:57 AM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by jackellyn View Post
    the printing of k-th digit

    P i k [Print k-th Digit ]
    Print out the k-th digit of integer i
    1st you want to put integer i into a string, use sprintf(). Then you extract the k-th digit...

    #include <stdio.h>
    int main(int argc, const char *argv[]) {
    	int eg = 1234;
    	char str[5];
    	sprintf(str, "%d", eg);
    	printf("3rd digit of %d = %c\n", eg, str[2]);
    	return 0;
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-16-2007, 10:39 PM
  2. Please help with a few things
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-24-2005, 01:24 PM
  3. Doing two things at once
    By eam in forum Linux Programming
    Replies: 7
    Last Post: 08-04-2004, 10:10 PM
  4. I have tried many things...
    By skyruler54 in forum C++ Programming
    Replies: 8
    Last Post: 09-05-2002, 07:17 PM
  5. how do i do these things?
    By knight543 in forum Windows Programming
    Replies: 1
    Last Post: 08-01-2002, 03:36 AM