Thread: converting an integer to a related number of spaces

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    Unhappy converting an integer to a related number of spaces

    OK so i am a university student just beggining in C, and I have this asignment which i have been struggling with, where we must take an input composing of two integers and an operator and create a 7 line output that looks something like this:
    Code:
          +-------------------+
          |0 1 2 3 4 5 6 7 8 9|
    +-----+-------------+-----+     (sorry about the formatting)
    |0 1 2 3 4 5 6 7 8 9|
    +-------------------+
                   ^
    What we must do is use the first input integer to shift the first three lines and use the second integer to shift the arow at the bottom. The operator will somehow determine the shift ratio, but i can figure that out later

    What i am really stuggling with is how can I use the input value for the integers to crate a number of spaces related to the value of that integer (ie if it is 3, print 6 spaces before each of the first 3 lines, if it is 4, print 4...etc (this only has to work for int 1-9)) and also how to cause this shift to effect the first three lines and not the next four

    Any input would be greatly appreciated

    Thankyou
    Last edited by Dave_Sinkula; 08-03-2006 at 05:20 PM. Reason: Tried to fix formatting with [code][/code] tags.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You could set up an array that contains strings of spaces of varying lenths:
    Code:
    char *spaces[] = { { "        " }, { "                " }, { "  " } ....<etc>... }
    
    ...
    
    printf("%s", spaces[num]);
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    2
    yes i would also like this answered

    cheers

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    yes i would also like this answered
    Umm, I did answer it.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Or

    Code:
    void printspace(int num) { while(num--) putchar(' '); }
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  2. Converting an integer into a string
    By Signifier in forum C++ Programming
    Replies: 3
    Last Post: 09-07-2007, 10:56 AM
  3. Replies: 7
    Last Post: 08-19-2007, 08:10 AM
  4. Replies: 5
    Last Post: 06-12-2007, 02:18 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM