different things to do, where to start?

This is a discussion on different things to do, where to start? within the C Programming forums, part of the General Programming Boards category; I'm supposed to do all these functions but i'm not sure how to do the printing of k-th digit C ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    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.
    help?

    Code:
    BC
    + -3 4
    + -4 -71
    - -41 -7
    H
    * 3 -5
    / 141 13
    / 14 -3
    H
    c F
    C f
    P 2143 3
    R 3.1415 2
    R 3.1415 3
    R 0.01015678 6
    H
    S -3.1415
    S 31.415
    D 9 40
    D 10 40
    D 90 90
    Q 
    c F
    C f
    H
    so far this is what i have
    Code:
    #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");
    	else
    		{
    	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')
    			printf("");
    		else if (operate == "R")
    			printf("");
    		else if (operate == "S")
    			printf("");
    		else if (operate == "D")
    			printf("");
    
    		}
    
    	return 0;
    }
    Last edited by jackellyn; 04-25-2011 at 07:57 AM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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...

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21