Click here to Skip to main content
15,868,016 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ memory question Pin
kanduripavan12-Jul-06 20:46
kanduripavan12-Jul-06 20:46 
GeneralRe: C++ memory question Pin
Joe Woodbury13-Jul-06 0:11
professionalJoe Woodbury13-Jul-06 0:11 
Questionsscanf will only put value in first variable Pin
Evilpixie12-Jul-06 11:32
Evilpixie12-Jul-06 11:32 
AnswerRe: sscanf will only put value in first variable [modified] Pin
earl12-Jul-06 12:46
earl12-Jul-06 12:46 
GeneralRe: sscanf will only put value in first variable Pin
Evilpixie12-Jul-06 13:11
Evilpixie12-Jul-06 13:11 
GeneralRe: sscanf will only put value in first variable Pin
earl12-Jul-06 13:14
earl12-Jul-06 13:14 
GeneralRe: sscanf will only put value in first variable Pin
Evilpixie12-Jul-06 13:17
Evilpixie12-Jul-06 13:17 
AnswerRe: sscanf will only put value in first variable Pin
Stephen Hewitt12-Jul-06 14:08
Stephen Hewitt12-Jul-06 14:08 
If you use C++ stream classes and strings instead of old non-typesafe C functions this kind of problem isn't possible. Here's a complete example with error checking:
---------------------------------
// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

int main(int argc, char *argv[])
{
using namespace std;

// Open the file.
ifstream ifs("C:\\a.txt");
if (!ifs)
{
cerr << "Failed to open input file!" << endl;
return 1;
}

// Read in line at a time.
unsigned int LineNumber = 1;
string Line;
while (getline(ifs, Line))
{
// Now break up the line.
istringstream iss(Line);
string PointID;
int x, y, z;
if (!(iss >> PointID >> x >> y >> z))
{
cerr << "Error in line " << LineNumber << endl;
return 2;
}
++LineNumber;

// Output the results to the console for testing.
cout << PointID << ": (" << x << ", " << y << ", " << z << ")" << endl;
}

return 0;
}

---------------------------------
You want to change it to read doubles. Just make the following change with no need to alter a format spec and manually make sure it matches the variables:
&nbsp;&nbsp;&nbsp; double x, y, z;


Steve
QuestionColor management in CDC Pin
TchouTchou Project12-Jul-06 11:23
TchouTchou Project12-Jul-06 11:23 
AnswerRe: Color management in CDC Pin
A_Fa12-Jul-06 20:09
A_Fa12-Jul-06 20:09 
QuestionHow can I convert to TIFF file format? [modified] Pin
Cris12-Jul-06 9:47
Cris12-Jul-06 9:47 
AnswerRe: How can I convert to TIFF file format? Pin
Christian Graus12-Jul-06 9:55
protectorChristian Graus12-Jul-06 9:55 
AnswerRe: How can I convert to TIFF file format? Pin
Joe Woodbury12-Jul-06 10:28
professionalJoe Woodbury12-Jul-06 10:28 
GeneralRe: How can I convert to TIFF file format? Pin
Cris13-Jul-06 2:00
Cris13-Jul-06 2:00 
GeneralRe: How can I convert to TIFF file format? Pin
Joe Woodbury13-Jul-06 8:19
professionalJoe Woodbury13-Jul-06 8:19 
AnswerRe: How can I convert to TIFF file format? Pin
earl12-Jul-06 12:42
earl12-Jul-06 12:42 
GeneralRe: How can I convert to TIFF file format? Pin
Cris13-Jul-06 1:45
Cris13-Jul-06 1:45 
GeneralRe: How can I convert to TIFF file format? Pin
earl13-Jul-06 5:12
earl13-Jul-06 5:12 
QuestionPlease,help me with jar-files in java Pin
beganovic_swe12-Jul-06 9:37
beganovic_swe12-Jul-06 9:37 
AnswerRe: Please,help me with jar-files in java Pin
Christian Graus12-Jul-06 9:43
protectorChristian Graus12-Jul-06 9:43 
GeneralRe: Please,help me with jar-files in java Pin
led mike12-Jul-06 9:49
led mike12-Jul-06 9:49 
GeneralRe: Please,help me with jar-files in java Pin
beganovic_swe12-Jul-06 22:33
beganovic_swe12-Jul-06 22:33 
QuestionCrash in MFC extension DLL [modified] Pin
act_x12-Jul-06 8:23
act_x12-Jul-06 8:23 
AnswerRe: Crash in MFC extension DLL Pin
led mike12-Jul-06 9:14
led mike12-Jul-06 9:14 
QuestionInvoke Self-Registration of an ActiveX Pin
Christopher Stratmann12-Jul-06 8:11
Christopher Stratmann12-Jul-06 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.