thorax232's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
95 (0.13 per day)
Joined:
10-September 12
Profile Views:
506
Last Active:
User is offline Nov 08 2013 09:13 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   thorax232 has not set their status

Posts I've Made

  1. In Topic: Convert integer to string - or print out specific numbers from integer

    Posted 8 Nov 2013

    View Post#define, on 08 November 2013 - 06:01 PM, said:

    Hi, you could use sprintf to write to a string, and then copy the characters to another string.


    You set me on the right path, thanks a ton!

    Finished/working code:
    #include <stdio.h>
    #include <string.h>
    
    struct telephone {
    	char name[80];
    	long long int number;
    }
    
    main() {
    
    	int amount = 0;
    	int i;
    
    	FILE *fp;
    	fp = fopen("phone.txt", "r");
    	fscanf(fp, " %d", &amount);
    	struct telephone list[amount];
    
    	// Scan in name and number records
    	for(i = 0; i < amount; i++) {
    		fscanf(fp, "%s", list[i].name);
    		fscanf(fp, " %lld", &list[i].number);
    	}
    	fclose(fp);
    	
    	// Sort lists (and display)
    	bubbleSort(list, amount);
    }
    
    bubbleSort(struct telephone *list, int amount) {
    	struct telephone temp;
    	int changed = 0; // Boolean 0 = false, 1 = true
    	int j, i;
    	
    	do {
    		changed = 0; // Resets on every pass
    		for(j = 0; j < amount - 1; j++) // Minus one because IF uses +1 to look at next
    			if(list[j].number > list[j + 1].number) {
    				temp = list[j]; // Shift value to temporary spot
    				list[j] = list[j + 1]; // Shift higher value into value i
    				list[j + 1] = temp; // Shift temp into higher value (swap)
    				changed = 1;
    			}
    	} while(changed = 0); // Stop when there is no change
    	
    	// Display lists
    	for(i = 0; i < amount; i++) {
    		DisplayStruct(list[i]);
    	}
    }
    
    DisplayStruct(struct telephone input) {
    	char str[80];
    	sprintf(str, "%lld %s\n", input.number, input.name); // Convert to string
    	printf("%.3s-%.3s-%4s", str, str + 3, str + 6);
    }
    
  2. In Topic: Recursive Function Using Substrings

    Posted 12 Oct 2013

    Wow, this is incredibly helpful. I'm tracing through the function and getting a lot out of it. Definately makes sense. Thanks so much!
  3. In Topic: [SOLVED] Get Input When Running Program From CMD

    Posted 17 Sep 2013

    View PostChrisNt, on 17 September 2013 - 04:15 PM, said:

    String args[] is to pass arguments to the program,just use them. First argument is args[0]


    ...You just blew my mind. Thanks!
  4. In Topic: Taking Turns in "Cootie" Game

    Posted 9 Sep 2013

    I've updated the program (in the Beetle Game class) and it still runs funny. The first roll goes without the user hitting enter and skips straight to player 2. Then the "roll count" is counting the total rolls of all players rather than for each specific one. Considering the die and roll methods are in seperate classes I don't see how this is happening. =/
  5. In Topic: Taking Turns in "Cootie" Game

    Posted 9 Sep 2013

    View Postjon.kiparsky, on 09 September 2013 - 12:32 PM, said:

    I have to confess that my brain started swimming a little as I tried to walk through your logic.


    This comes from a book, and while I've added a lot to it, the logic isn't really mine.

    The problem isn't necessarily incrementing the player so much as incrementing the object. Each player has their own "beetle" in which they are trying to build.

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

thorax232 hasn't added any friends yet.

Comments

thorax232 has no profile comments yet. Why not say hello?