New Posts  All Forums:Forum Nav:

[Solved] C switch-statement

post #1 of 3
Thread Starter 
So in a program of mine, I have the switch-statement below and for some reason it's changing two variables- a char and a char array- without me even mentioning it in the switch statement. Through some printf testing I am almost certain this switch statement is the cause, but I have no idea why. The char, at least, seems to be setting itself to output2[1] Any idea why?


Code:
          for (i=0; i<9; i++)
          {
              switch (output1[i])
              {
                     case 1:
                          output2[i] = 'a';
                          break;
                     case 2:
                          output2[i] = 'b';
                          break;
                     case 3:
                          output2[i] = 'c';
                          break;
                     case 4:
                          output2[i] = 'd';
                          break;
                     case 5:
                          output2[i] = 'e';
                          break;
                     case 6:
                          output2[i] = 'f';
                          break;
                     case 7:
                          output2[i] = 'g';
                          break;
                     case 8:
                          output2[i] = 'h';
                          break;
                     case 9:
                          output2[i] = 'i';
                          break;
                     case 10:
                          output2[i] = 'j';
                          break;
                     case 11:
                          output2[i] = 'k';
                          break;
                     case 12:
                          output2[i] = 'l';
                          break;
                     case 13:
                          output2[i] = 'm';
                          break;
                     case 14:
                          output2[i] = 'n';
                          break;
                     case 15:
                          output2[i] = 'o';
                          break;
                     case 16:
                          output2[i] = 'p';
                          break;
                     case 17:
                          output2[i] = 'q';
                          break;
                     case 18:
                          output2[i] = 'r';
                          break;
                     case 19:
                          output2[i] = 's';
                          break;
                     case 20:
                          output2[i] = 't';
                          break;
                     case 21:
                          output2[i] = 'u';
                          break;
                     case 22:
                          output2[i] = 'v';
                          break;
                     case 23:
                          output2[i] = 'w';
                          break;
                     case 24:
                          output2[i] = 'x';
                          break;
                     case 25:
                          output2[i] = 'y';
                          break;
                     case 26:
                          output2[i] = 'z';
                          break;
                     default: 
                          if (output1[i] > 26 || output1[i] < 1)
                          {
                                 output2[i] = toupper(s1[i]);
                          }
                          break;
              }
          }

Edited by Haleiwa Salt - 2/23/11 at 6:53pm
Late 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-950 3.06GHz (OC to 3.8GHz stable) ASUS Sabertooth X58 LGA 1366 EVGA GeForce GTX 460 1GB 12GB (6x2GB) G.SKILL DDR3 1600 (PC3 12800) 
Hard DriveOptical DriveOSMonitor
1TB Hitachi Deskstar 7200 RPM 32MB Cache HP dvd1260 Windows 7 23" Dell U2311H 
PowerCase
Corsair 750TX 750W Cooler Master HAF 932 Full Tower 
  hide details  
Reply
Late 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-950 3.06GHz (OC to 3.8GHz stable) ASUS Sabertooth X58 LGA 1366 EVGA GeForce GTX 460 1GB 12GB (6x2GB) G.SKILL DDR3 1600 (PC3 12800) 
Hard DriveOptical DriveOSMonitor
1TB Hitachi Deskstar 7200 RPM 32MB Cache HP dvd1260 Windows 7 23" Dell U2311H 
PowerCase
Corsair 750TX 750W Cooler Master HAF 932 Full Tower 
  hide details  
Reply
post #2 of 3
Try creating a temp int in the

Code:
for (i=0; i<9; i++)
          {

//Create temp integer here before the switch statement  int temp = i

              switch (output1[temp])
              {

Then change the calls from [i] to [temp] accordingly
See if that changes anything.
Edited by mykah89 - 2/23/11 at 6:35pm
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
I5 760 GA-H55N GTX 470 PNY Optima 8GB 
Hard DriveMonitorPowerCase
Spinpoint F4 LG227WTG sg07 PSU Sugo sg07 
Mouse
CM Sentinel 
  hide details  
Reply
post #3 of 3
Thread Starter 
I got it sorted out, actually; I had to explicitly state my outputs as output1[9] and output2[9] instead of initializing them as output1[], etc. Thanks though!
Late 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-950 3.06GHz (OC to 3.8GHz stable) ASUS Sabertooth X58 LGA 1366 EVGA GeForce GTX 460 1GB 12GB (6x2GB) G.SKILL DDR3 1600 (PC3 12800) 
Hard DriveOptical DriveOSMonitor
1TB Hitachi Deskstar 7200 RPM 32MB Cache HP dvd1260 Windows 7 23" Dell U2311H 
PowerCase
Corsair 750TX 750W Cooler Master HAF 932 Full Tower 
  hide details  
Reply
Late 2010
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-950 3.06GHz (OC to 3.8GHz stable) ASUS Sabertooth X58 LGA 1366 EVGA GeForce GTX 460 1GB 12GB (6x2GB) G.SKILL DDR3 1600 (PC3 12800) 
Hard DriveOptical DriveOSMonitor
1TB Hitachi Deskstar 7200 RPM 32MB Cache HP dvd1260 Windows 7 23" Dell U2311H 
PowerCase
Corsair 750TX 750W Cooler Master HAF 932 Full Tower 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming