Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programmers' lounge. (Programming-related discussions only)
New Posts  All Forums:Forum Nav:

Programmers' lounge. (Programming-related discussions only) - Page 54

post #531 of 1143
Quote:
Originally Posted by Icekilla View Post

Hey guys. I'm having a little problem with conversion from character to integer.

I have a project where I have to do this, and that part just won't work. Because of that, I decided to make a small code to test a function named sscanf, which should convert a character, or string, into a number.

Here's the code. However, it won't work.
Warning: Spoiler! (Click to show)
[#include <stdio.h> #include <stdlib.h> int main() { char a, b; int a1 = 0, b1 = 0; printf("Gimme a number\n"); scanf("%c", &a); scanf ("%*[^\n]"); getchar(); printf("Gimme a number\n"); scanf("%c", &b); scanf ("%*[^\n]"); getchar(); sscanf(a, "%d", &a1); sscanf(b, "%d", &b1); printf("num 1: %d\n", a1); printf("num 1: %d\n", b1); getchar(); return 0; } /CODE][/SPOILER] When I reach the data type conversion, the program crashes. Anyone knows why?[/quote]The code formatting's not right, its unreadable. Wrap the code tags :P[code][#include
#include

int main()
{
char a, b;
int a1 = 0, b1 = 0;

printf("Gimme a number\n");
scanf("%c", &a);

scanf ("%*[^\n]");
getchar();

printf("Gimme a number\n");
scanf("%c", &b);

scanf ("%*[^\n]");
getchar();

sscanf(a, "%d", &a1);
sscanf(b, "%d", &b1);

printf("num 1: %d\n", a1);
printf("num 1: %d\n", b1);

getchar();

return 0;
}
/CODE]

When I reach the data type conversion, the program crashes. Anyone knows why?
The code formatting's not right, its unreadable. Wrap the code tags tongue.gif
post #532 of 1143
Sorry XD

Fixed

Just to let you know, I changed sscanf for atoi.

NEVERMIND: I used this and it worked
Code:
a = ach - '0';
b = bch - '0';

Edited by Icekilla - 3/12/13 at 4:19pm
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
post #533 of 1143
So the problem is that the input for atoi is that it takes a pointer. So if you
Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *  a = "123";
    char *  b = "456";
    
    printf("%d\n", atoi(a));
    printf("%d\n", atoi(b));

    return 0;
}


That will fix it.

Of course your solution will only work on characters and not strings.

Of course with C you would have to limit your input size otherwise you would get buffer overflow with just these C-Strings if you were to use scanf,

A more correct way to take integer input in C would be to just use scanf("%d", &myint).
Edited by Luminouslight - 3/12/13 at 5:27pm
 
El Escorial
(17 items)
 
La Reconquista
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770K GA-Z87-UD5H MSI GeForce GTX 780 G.SKILL Trident X 10-12-12-31 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro Samsung F3 XSPC Raystorm CPU Waterblock XSPC Razor GTX Titan/GTX780 
OSOSMonitorMonitor
Gentoo x86_64 Windows 7 Professional 64 bit QNIX QX2710 Gateway FHD2401 
KeyboardPowerCaseMouse
Filco Majestouch-2 Tenkeyless Seasonic SS-760XP2 Fractal Define R4 Window Logitech G500 
Audio
Asus Xonar Essence STX 
CPUMotherboardGraphicsRAM
Intel Core i7 D0 @ 4.0 Ghz Gigabyte GA-EX58-UD3R PNY GTX 470 OCZ 6GB DDR3 1600 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Green Samsung F3 Western Digital Blue x16 DVD-ROM burner 
OSOSMonitorMonitor
Arch Linux Windows 7 Professional x64 Qnix QX2710 Gateway FHD2401 24" 
KeyboardPowerCaseMouse
Filco Majestictouch Corsair 650w CM 690 II Logitech G500 
CPUMotherboardGraphicsRAM
AMD 64 Athlon San Diego 4000+ MSI MS-7191 XFX Nvidia Geforce 7800gt 2 Gig DDR 400 
Hard DriveOSMonitorKeyboard
Seagate 250 gig Harddrive Windows XP SP3 COMPAQ 7500 COMPAQ default 
PowerCaseMouseMouse Pad
"Power Up" 550 Watt XION Solaris XON-406 Logitech Lazer Mouse Fate/Stay Night Mouse Pad 
  hide details  
Reply
 
El Escorial
(17 items)
 
La Reconquista
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770K GA-Z87-UD5H MSI GeForce GTX 780 G.SKILL Trident X 10-12-12-31 
Hard DriveHard DriveCoolingCooling
Samsung 840 Pro Samsung F3 XSPC Raystorm CPU Waterblock XSPC Razor GTX Titan/GTX780 
OSOSMonitorMonitor
Gentoo x86_64 Windows 7 Professional 64 bit QNIX QX2710 Gateway FHD2401 
KeyboardPowerCaseMouse
Filco Majestouch-2 Tenkeyless Seasonic SS-760XP2 Fractal Define R4 Window Logitech G500 
Audio
Asus Xonar Essence STX 
CPUMotherboardGraphicsRAM
Intel Core i7 D0 @ 4.0 Ghz Gigabyte GA-EX58-UD3R PNY GTX 470 OCZ 6GB DDR3 1600 
Hard DriveHard DriveHard DriveOptical Drive
Western Digital Green Samsung F3 Western Digital Blue x16 DVD-ROM burner 
OSOSMonitorMonitor
Arch Linux Windows 7 Professional x64 Qnix QX2710 Gateway FHD2401 24" 
KeyboardPowerCaseMouse
Filco Majestictouch Corsair 650w CM 690 II Logitech G500 
CPUMotherboardGraphicsRAM
AMD 64 Athlon San Diego 4000+ MSI MS-7191 XFX Nvidia Geforce 7800gt 2 Gig DDR 400 
Hard DriveOSMonitorKeyboard
Seagate 250 gig Harddrive Windows XP SP3 COMPAQ 7500 COMPAQ default 
PowerCaseMouseMouse Pad
"Power Up" 550 Watt XION Solaris XON-406 Logitech Lazer Mouse Fate/Stay Night Mouse Pad 
  hide details  
Reply
post #534 of 1143
Any tips to translate Windows API to Delphi?axesmiley.png

Delphi XE3 here.tongue.gif
post #535 of 1143
Do people still use Delphi? I though it was deprecated.
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
fr0sty
(20 items)
 
SnowFlake
(5 items)
 
 
CPURAMHard DriveHard Drive
Intel Core i7 3520M  Corsair Vengeance DDR3 2x 8GB Samsung EVO SSD Hitachi Apple Hard Drive 5400RPM 
OS
macOS Sierra 
  hide details  
Reply
post #536 of 1143
Quote:
Originally Posted by Icekilla View Post

Do people still use Delphi? I though it was deprecated.
It isn't.
post #537 of 1143
Im probably rather late to the joke, but my coding teacher showed us Google's recursion joke today. Hehe.
Recursion isnt too hard honestly (in java, for me). Granted we haven't gotten into super hard recursion yet I think, though we have done questions that would be on an AP exam (Basically around a 2nd year Comp Sci major class).
Wrecking Ball.
(18 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i5 2500K Asus p8z68-v/gen 3 Asus 670 top 16 GB (total) G.skill ripjaws 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Seagate 1TB 7200rpm HDD Crucial M4 256GB ASUS 24x CD/DVD drive Corsair H80i 
OSMonitorPowerCase
Windows 7 home viewsonic 27 inch 1ms response Corsair AX750 NZXT Switch 810 
MouseAudioAudio
razer deathadder turtle beach x12 Sennheiser HD280 
CPUMotherboardGraphicsGraphics
Intel i7 3770k ASUS p8z68-vpro/gen3 Gigabyte 7950 3gb Gigabyte 7950 3gb 
RAMRAMHard DriveCooling
GSkill Ripjaws X 8gb 2133mhz G skill Ripjaws X 8gb 2133mhz Crucial M4 512gb ssd Corsair H100i 
MonitorKeyboardPowerCase
Auria 1440P 27" IPS Ducky OCN Cherry MX blue Silverstone 1000w NZXT switch 810 
Audio
ASUS xonar DG 
  hide details  
Reply
Wrecking Ball.
(18 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i5 2500K Asus p8z68-v/gen 3 Asus 670 top 16 GB (total) G.skill ripjaws 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Seagate 1TB 7200rpm HDD Crucial M4 256GB ASUS 24x CD/DVD drive Corsair H80i 
OSMonitorPowerCase
Windows 7 home viewsonic 27 inch 1ms response Corsair AX750 NZXT Switch 810 
MouseAudioAudio
razer deathadder turtle beach x12 Sennheiser HD280 
CPUMotherboardGraphicsGraphics
Intel i7 3770k ASUS p8z68-vpro/gen3 Gigabyte 7950 3gb Gigabyte 7950 3gb 
RAMRAMHard DriveCooling
GSkill Ripjaws X 8gb 2133mhz G skill Ripjaws X 8gb 2133mhz Crucial M4 512gb ssd Corsair H100i 
MonitorKeyboardPowerCase
Auria 1440P 27" IPS Ducky OCN Cherry MX blue Silverstone 1000w NZXT switch 810 
Audio
ASUS xonar DG 
  hide details  
Reply
post #538 of 1143
I know it's not the same, but I didn't really know where else to post about this.

I'm trying to transfer from mechanical engineering to computer science. Engineering just isn't what I thought it was going to be like, and I really don't enjoy it even a fraction of what I thought I would. So I'm considering the change, but from bouncing around in here for a while tonight, it sounds like computer science degrees can't get you employed very easily. Is this true? I'm just hoping I'm not throwing away something big.
HAFaestus
(18 items)
 
  
CPUMotherboardGraphicsRAM
FX-8120 ASUS Sabertooth 990FX ASUS DirectCU GTX 460 2 x 4GB Samsung 
Hard DriveHard DriveHard DriveOptical Drive
128GB M4 250GB Seagate 1TB WD Black LG 20X DualLayer 
OSMonitorKeyboardPower
Windows 7 Professional 64-bit HP w2338h Chicony KB-2961 SeaSonic X750 80+Gold 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Black Interior Logitech G9x Razer Goliathus Extended Razer Carcharias 
AudioAudio
Denon AVR-1712 Klipsch Qunitet 
  hide details  
Reply
HAFaestus
(18 items)
 
  
CPUMotherboardGraphicsRAM
FX-8120 ASUS Sabertooth 990FX ASUS DirectCU GTX 460 2 x 4GB Samsung 
Hard DriveHard DriveHard DriveOptical Drive
128GB M4 250GB Seagate 1TB WD Black LG 20X DualLayer 
OSMonitorKeyboardPower
Windows 7 Professional 64-bit HP w2338h Chicony KB-2961 SeaSonic X750 80+Gold 
CaseMouseMouse PadAudio
Cooler Master HAF 932 Black Interior Logitech G9x Razer Goliathus Extended Razer Carcharias 
AudioAudio
Denon AVR-1712 Klipsch Qunitet 
  hide details  
Reply
post #539 of 1143
Not strictly programming, but here goes:
V1, adf.ly has fixed this! (Click to show)
How to skip adf.ly links:
  1. Add a bookmark containing
    Code:
    javascript:countdown=0; window.location.href=zzz;
    
    as the target.
  2. Go to ad.fly link
  3. Click bookmark
  4. Let person who made whatever you're downloading get profit without waiting an age for it.

adf.ly has fixed it now frown.gif I'm still trying to find another way of doing it.
Edited by 3930K - 3/27/13 at 12:45pm
post #540 of 1143
Why should you do this instead of this?
Code:
public int number;
Code:
public int number { get; set; }

I have done some reading and most people say only use properties in an interface. and properties are a wast of free space for other code. Is that true?
    
CPUMotherboardGraphicsRAM
Intel 3930K 5040MHz @ 1.48 - 1.53v @ VTT/VCCSA ... Asus rampage extreme IV Gigabyte GTX 970 G1 @ 1580/4050MHz @ 1.325V Corsair Vengeance 64GB (8 x 8GB) DDR3 2400MHz. ... 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 Pro 256GB Seagate Barracuda ST3000DM001 3TB WD Black 1TB 64Mb Cache  WD Blue 500GB 16mb Cache 
Hard DriveOptical DriveCoolingCooling
WD Black 4TB 64mb Cache LG DVD EK-FB KIT RE4 - Acetal EK-FC970 GTX WF3 Backplate - Black 
CoolingCoolingCoolingCooling
Laing D5 Vario 12V DC Pump (MCP 655)  EK-BAY SPIN Reservoir - Plexi EK-CoolStream RAD XT (240) EK-CoolStream RAD XTX (120) 
CoolingCoolingCoolingCooling
EK-CoolStream XE 120 (Single) 8x Corsair Air SP120 PWM High Performance Edition 3x Corsair Air AF120 High Performance Edition EK-Supremacy EVO CPU Water Block (Nickel Acetal) 
CoolingOSMonitorMonitor
EK-FC970 GTX WF3 - Acetal+Nickel Windows 10 64-bit v1511 build 10586.14 BenQ RL2755HM LG W2261 
MonitorKeyboardPowerCase
Samsung S23C350 Razer BlackWidow Ultimate Cooler Master Silent Pro Gold 1000W Thermaltake Level 10 GT 
Mouse
Razer Lachesis 5600DPI 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel 3930K 5040MHz @ 1.48 - 1.53v @ VTT/VCCSA ... Asus rampage extreme IV Gigabyte GTX 970 G1 @ 1580/4050MHz @ 1.325V Corsair Vengeance 64GB (8 x 8GB) DDR3 2400MHz. ... 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 Pro 256GB Seagate Barracuda ST3000DM001 3TB WD Black 1TB 64Mb Cache  WD Blue 500GB 16mb Cache 
Hard DriveOptical DriveCoolingCooling
WD Black 4TB 64mb Cache LG DVD EK-FB KIT RE4 - Acetal EK-FC970 GTX WF3 Backplate - Black 
CoolingCoolingCoolingCooling
Laing D5 Vario 12V DC Pump (MCP 655)  EK-BAY SPIN Reservoir - Plexi EK-CoolStream RAD XT (240) EK-CoolStream RAD XTX (120) 
CoolingCoolingCoolingCooling
EK-CoolStream XE 120 (Single) 8x Corsair Air SP120 PWM High Performance Edition 3x Corsair Air AF120 High Performance Edition EK-Supremacy EVO CPU Water Block (Nickel Acetal) 
CoolingOSMonitorMonitor
EK-FC970 GTX WF3 - Acetal+Nickel Windows 10 64-bit v1511 build 10586.14 BenQ RL2755HM LG W2261 
MonitorKeyboardPowerCase
Samsung S23C350 Razer BlackWidow Ultimate Cooler Master Silent Pro Gold 1000W Thermaltake Level 10 GT 
Mouse
Razer Lachesis 5600DPI 
  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 › Programmers' lounge. (Programming-related discussions only)