Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Any idea of what's wrong with my tolower? (C code)
New Posts  All Forums:Forum Nav:

Any idea of what's wrong with my tolower? (C code)

post #1 of 9
Thread Starter 
Here's my code

http://pastebin.com/hexSmDsG

The problem lies in the lines 23 and 33 (They're in fact, commented).

What I want is that once the string is read, it turns all of the characters to lowercase so it can be easier to search for the data, but so far, no luck.

Any help? biggrin.gif
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
post #2 of 9
tolower() takes a single character and you'll passing it a char array. You need to iterate through characters in your string and convert each one individually.
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #3 of 9
Thread Starter 
Like this?
Code:
for(w=0;w<strlen(country[i]);w++)
         country[i]=tolower(country[w])

Then again, codeblocks kepes throwing errors.

EDIT: How about now?

http://pastebin.com/Yhj7wy6x
Edited by Icekilla - 11/8/12 at 3:14pm
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
post #4 of 9
http://codepad.org/C6sMqiKI

Gets you a line 69 error.
post #5 of 9
Thread Starter 
How about now? Running it in CodeBlocks seems decent.

http://pastebin.com/TsRakggL
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
post #6 of 9
Quote:
Originally Posted by Icekilla View Post

How about now? Running it in CodeBlocks seems decent.

http://pastebin.com/TsRakggL

You should not declare variables outside of the scope that they are needed, or before they are needed. You should give variables useful names so people can easily know what they're being used for. You should not declare more than one variable per line.

You're using the second dimension of your array 'country' before it is initialized to anything. You're also using the first dimension in that array unsafely. Generally you will want to initialize each index in the array to a default value, often zero. You can use memset to do this since the array is using a primitive data type. I would work on getting the array properly initialized and filled with data and then the tolower should work.
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
post #7 of 9
Thread Starter 
The thing is, everything is working now... Should I still optimize it, though?
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
post #8 of 9
Quote:
Originally Posted by Icekilla View Post

The thing is, everything is working now... Should I still optimize it, though?

If it's never going to be used again or by anyone else, then I wouldn't clean it up unless you want to do it for practice.
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
Foldatron
(17 items)
 
Mat
(10 items)
 
Work iMac
(9 items)
 
CPUMotherboardGraphicsGraphics
i7 950 EVGA x58 3-way SLI EVGA GTX 660ti GTX 275 
RAMHard DriveHard DriveHard Drive
3x2GB Corsair Dominator DDR3-1600 80GB Intel X25-M SSD 2TB WD Black 150GB WD Raptor 
Hard DriveOSMonitorKeyboard
2x 150GB WD V-raptor in RAID0 Win7 Home 64-bit OEM 55" LED 120hz 1080p Vizio MS Natural Ergonomic Keyboard 4000 
PowerCase
750W PC P&C Silencer CoolerMaster 690 
CPUGraphicsRAMHard Drive
Intel Core i5 2500S AMD 6770M 8GB (2x4GB) at 1333Mhz 1TB, 7200 rpm 
Optical DriveOSMonitorKeyboard
LG 8X Dual-Layer "SuperDrive" OS X Lion 27" iMac screen Mac wireless keyboard 
Mouse
Mac wireless mouse 
CPUGraphicsRAMHard Drive
i7-2600K AMD 6970M 1GB 16GB PC3-10600 DDR3 1TB 7200rpm 
Hard DriveOptical DriveOSMonitor
256GB SSD 8x DL "SuperDrive" OS X 10.7 Lion 27" 2560x1440 iMac display 
Monitor
27" Apple thunderbolt display 
  hide details  
Reply
post #9 of 9
Thread Starter 
It's just for a homework, but I guess it'd be a good practice.
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
Vanessa
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500k Gigabyte GA-Z77-D3H EVGA GTX 660ti SuperClocked PNY Optima MD4096SD3-1333 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital WD500AAKX 500GB SATA Seagate ST2000DL003 ADATA AS510S3-120GM-C 120GB SSD Lite-On iHAS224-06 
CoolingOSMonitorMonitor
Cooler Master Hyper 212+ Windows 7 Ultimate x64 Samsung B1930  Benq G92HDA 
PowerCaseAudio
Corsair TX750 750W PSU Gray Acteck Octanux Logitech Z623 2.1CH 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Any idea of what's wrong with my tolower? (C code)