home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Who wants to debug some code?

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2088
Discussions: 200,948, Posts: 2,379,406, Members: 246,309
Old December 12th, 2005, 05:38 AM   Digg it!   #1 (permalink)
Member
 
Join Date: Dec 2005
Posts: 127
Who wants to debug some code?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int i;
int j;
int* k;
int l;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char characterArray[78] = 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '`' '~' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '_' '=' '+' '\\' '/' '\'' '\"\' '.' ',';

j = sizeof(characterArray);

int main(void) {
    
    srand(time(NULL)); /*Seed the rand() function*/
    
    for(i = 0;i<10;i++) { /*Loop for inserting numbers*/
        numbers1[i] = rand % 9;
        numbers2[i] = rand % 9;
        numbers3[i] = rand % 9;
        numbers4[i] = rand % 9;
        numbers5[i] = rand % 9;
        numbers6[i] = rand % 9;
        numbers7[i] = rand % 9;
        numbers8[i] = rand % 9;
        numbers9[i] = rand % 9;
        numbers10[i] = rand % 9;
        
    }
    
    for(i = 0;i<10;i++) { /*Loop for inserting characters*/
        l = rand() % j;
        k = &characterArray[l];
        
        numbers1[l] = *k;
        numbers2[l] = *k;
        numbers3[l] = *k;
        numbers4[l] = *k;
        numbers5[l] = *k;
        numbers6[l] = *k;
        numbers7[l] = *k;
        numbers8[l] = *k;
        numbers9[l] = *k;
        numbers10[l] = *k;
        
    }
    
    printf("Generated passwords:\n\n %s\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s\s", numbers1[], numbers 2[], numbers3[], numbers4[], numbers5[], numbers6[], numbers7[], numbers8[], numbers9[], numbers10[]);
    
    system("pause");
    
    return 0;
    
}
Hacked that up a few hours ago for a friend... it's suppose to be a password generator. Anyone know what the issues with the syntax are?
zSilverFox is offline   Reply With Quote
Old December 12th, 2005, 05:47 AM     #2 (permalink)
It's the cheese guy! ¬_¬;
 
paul9's Avatar
 
Join Date: Aug 2003
Location: Gateshead U.K.
Posts: 9,167
Send a message via MSN to paul9 Send a message via Yahoo to paul9
int* k looks a bit off, as does '=' '+' '\\' '/' '\'' '\"\' '.' ',';
paul9 is offline   Reply With Quote
Old December 21st, 2005, 12:22 AM     #3 (permalink)
Member
 
Join Date: May 2005
Location: NYC
Posts: 370
Send a message via AIM to sunny22
what language is that?
__________________
MSI K8N Neo4 Platinum SLI Socket 939 nForce4
Athlon 64 3200+ Venice Socket 939
CORSAIR XMS 2GB 184-Pin DDR 400 (PC 3200)
ATI x800xl PCI Express
sunny22 is offline   Reply With Quote
Old December 21st, 2005, 12:25 AM     #4 (permalink)
Member
 
Join Date: Oct 2005
Location: Australia
Posts: 58
i tink its C++...
oliver w is offline   Reply With Quote
Old December 21st, 2005, 12:37 AM     #5 (permalink)
Member
 
Join Date: Dec 2005
Posts: 127
It's C.

Final updated code, courtesy of help from a friend:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

/*
  Variables
*/
int i, l;
char* k;

char numbers1[10];
char numbers2[10];
char numbers3[10];
char numbers4[10];
char numbers5[10];
char numbers6[10];
char numbers7[10];
char numbers8[10];
char numbers9[10];
char numbers10[10];

char characterArray[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*'};
int j = sizeof(characterArray);

/*
  Prototypes
*/
void InsertRandomCharacter(char *, int);

/*
  Functions
*/
void InsertRandomCharacter(char *ar, int slot) {
   l = rand() % j;
   k = &characterArray[l];

   ar[slot] = *k;
}

int main(void) {
  srand(time(NULL)); /*Seed the rand() function*/

  for (i = 0; i < 10; i++) { /*Loop for inserting numbers*/
      numbers1[i] = rand() % 9;
      numbers2[i] = rand() % 9;
      numbers3[i] = rand() % 9;
      numbers4[i] = rand() % 9;
      numbers5[i] = rand() % 9;
      numbers6[i] = rand() % 9;
      numbers7[i] = rand() % 9;
      numbers8[i] = rand() % 9;
      numbers9[i] = rand() % 9;
      numbers10[i] = rand() % 9;

  }

  for (i = 0; i < 10; i++) { /*Loop for inserting characters*/
       InsertRandomCharacter(numbers1, i);
       InsertRandomCharacter(numbers2, i);
       InsertRandomCharacter(numbers3, i);
       InsertRandomCharacter(numbers4, i);
       InsertRandomCharacter(numbers5, i);
       InsertRandomCharacter(numbers6, i);
       InsertRandomCharacter(numbers7, i);
       InsertRandomCharacter(numbers8, i);
       InsertRandomCharacter(numbers9, i);
       InsertRandomCharacter(numbers10, i);
  }

   printf("Generated Passwords:\n\n");
   for (i = 0; i < 10; i++) {
       printf("%d. %c%c%c%c%c%c%c%c%c%c%c\n", i, numbers1[i], numbers2[i], numbers3[i], numbers4[i], numbers5[i], numbers6[i], numbers7[i], numbers8[i], numbers9[i], numbers10[i]);
   }

  system("pause");

  return 0;

}

Last edited by zSilverFox : December 21st, 2005 at 12:42 AM.
zSilverFox is offline   Reply With Quote
Old December 22nd, 2005, 01:24 AM     #6 (permalink)
Senior Member
 
Join Date: May 2003
Location: Aus, Gold Coast :)
Posts: 802
Send a message via ICQ to exally
Exally suggests a 2 dimensional array instead of tht monstrosity of naming convention....

char numbers[10][10];

much nicer and easier to iterate through....
exally is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with debug.exe indianj Webmastering and Programming 1 December 11th, 2005 11:26 PM
AIM and a debug message J'rd Technical Support 2 November 13th, 2003 09:30 PM
Using the Debug Utility Ifontoc Applications and Operating Systems 1 August 20th, 2002 03:43 AM
What do you use to debug in C/C++? Fractile81 Webmastering and Programming 6 April 2nd, 2002 04:31 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Making Health Care Worse (174)
Is It Just Me? (2938)
The disrespect of Obama by Russian .. (23)
Wireless Televisions. (12)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (6)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (5)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
For Sale BFG GTX285 OC2 with 10 year .. (3)
Point and Shoot Camera Suggestions. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Graphics Card Upgrade Question (3)
Laptop with wireless problem. (2)
Internet Lost (1)
Hp Artist Edition + Matching Bag (0)
My monitor won't turn on after instal.. (0)
Asus P4G8X Mobo (6)
radeon x850xt platinum & shader 3 (5)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
Multiple Restarts Required at Boot (0)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Have you switched yet? (86)
screen resolution vs monitor size (2)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)


All times are GMT -4. The time now is 09:44 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28