|
Hello, i'm doing a simple ansi c console application.
i'm reading a file
Now, i have to print its characters, and if i find a non-printable character i'd like to write a . or , or whatever.
i've got this code that prints everything:
while (Cantidad>0)
{
c=getc(Arch);
if (c!=EOF)
printf("%c",c);
else
{
printf("eof.\n");
return 1;
}
Cantidad--;
}
how do i check if c is a non-printable character?
thanks!
|
|
|
|
|
|
thanks!!
that function solved it!
|
|
|
|
|
Hi, can somebody help me?
I am beginning study C++, but I confuse with multiple source and header file function call.
Example:
engine.cpp have function below
double Engine::GetWeight(){
return mWeight;
}
car.cpp have function below
void Car::UpdateWeight(){
}
The car.h file include engine.h file but they are not inheritance "is - a", how can I call engine GetWeight() function or get the engine mWeight result at car.cpp file? Many thanks.
|
|
|
|
|
As you say, there is no IS-A relationship between a car and an engine. But there's a HAS-A relationship: manely, a car has an engine (and only one, if you restrict your program to the usual cases.) HAS-A is modelled in C++ typically by member variables:
class Car
{
...
Engine engine;
}; It is up to you to decide on other details, like whether engine is to be made public or private . Now, on your Car::UpdateWeight implementation you can access the engine interface the usual way:
void Car::UpdateWeight(){
double engine_weight=engine.GetWeight();
...
} Does this clear the issue to you?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
Thanks your reply. But I still have problem when I compile car.cpp file and below is detail information of car.h, car.cpp, engine.h and engine.cpp. Can you help me again, many thanks.
engine.h file
#ifndef ENGINE_H
#define ENGINE_H
class Engine {
public:
Engine();
Engine(double p, double w, double price, double maxp);
~Engine();
double GetPower();
double GetWeight();
double GetPrice();
double GetMaxPower();
protected:
double mPower;
double mWeight;
double mPrice;
double mMaxPower;
};
#endif
engine.cpp file
#include <iostream.h>
#include "engine.h"
Engine::Engine(){
mPower = 0 ; mWeight = 0 ; mPrice = 0 ; mMaxPower = 0;
}
Engine::Engine(double p, double w, double price, double maxp){
mPower = p;mWeight = w;mPrice = price;mMaxPower = maxp;
}
Engine::~Engine(){
}
double Engine::GetPower(){
return mPower;
}
double Engine::GetWeight(){
return mWeight;
}
double Engine::GetPrice(){
return mPrice;
}
double Engine::GetMaxPower(){
return mMaxPower;
}
Car.h file
#ifndef CAR_H
#define CAR_H
#include "engine.h"
#include "gearbox.h"
#include "carbody.h"
class Car{
public:
Car();
Car(Engine& e, GearBox& g, CarBody& b);
~Car();
double GetWeight();
double GetPrice();
double GetMaxSpeed();
void SpeedUp();
void SpeedDown();
double GetCurrentSpeed();
protected:
double mCurrentSpeed;
double mMaxSpeed;
double mWeight;
double mPrice;
Engine mEngine;
GearBox mGearBox;
CarBody mCarBody;
void UpdateWeight();
void UpdatePrice();
void UpdateMaxSpeed();
};
#endif
Car.cpp file
#include <iostream.h>
#include "car.h"
Car::Car(){
mCurrentSpeed = 0 ; mMaxSpeed = 0 ; mWeight = 0 ; mPrice = 0;
}
Car::Car(Engine& e, GearBox& g, CarBody& b){
mEngine = e ; mGearBox = g ; mCarBody = b;
}
Car::~Car(){
}
void Car::UpdateWeight(){
double mWeight=Engine.GetWeight();
}
But when I compile only car.cpp file and it point to "double mWeight=Engine.GetWeight" and display below error message.
Compiling...
Car.cpp
F:\c++\My05\Car.cpp(18) : error C2275: 'Engine' : illegal use of this type as an expression
f:\c++\my05\engine.h(4) : see declaration of 'Engine'
|
|
|
|
|
Your code should have double mWeight = mEngine.GetWeight(); instead. You call a class member funnction through an object of that class, not by the class name.
|
|
|
|
|
badbirdchung wrote:
how can I call engine GetWeight() function or get the engine mWeight result at car.cpp file?
Have you declared an instance of Engine in your Car class's header file?
#include "Engine.h"
class Car
{
[...]
Engine m_engine;
[...]
};
Then in your Car 's C++ implentation file, you can call member functions of your "m_engine " instance whenever you need it. For instance:
m_engine.GetWeight();
I hope this clearifies things for you.
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
N-Tech Productions
http://www.n-tp.com/
|
|
|
|
|
how to write text to RichEdit line by line.
for example
...
WriteText("line1\r\n");
...
...
WriteText("line2\r\n");
...
...
WriteText("line2\r\n");
...
I tried SetWindowText(), but it CLEARS the existing text and writes the text at the first line.
|
|
|
|
|
use the member function CEdit::ReplaceSel(LPCTSTR str) . know that CRichEdit inherits from the CEdit class, that's allowed
TOXCCT >>> GEII power
|
|
|
|
|
HI,
1 - How can i detect the that on which path Program Files Folder is ???
2- and how can i find path of specific folder
thanx
Regards.
|
|
|
|
|
About your first question.
You can read the ProgramFilesDir value at:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion
in Registry. Then you will obtain the current path of the Program Files Folder in the system.
You can use RegOpenKey and RegQueryValueEx Windows API functions to read the path from the Registry.
|
|
|
|
|
HI,
How can i detect the that on which path Program Files Folder is ???
thanx
Regards.
|
|
|
|
|
ShGetSpeacialFolderPath ,ShGetFolderPath api will help you in above cause
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Well you can read from regedit
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
"ProgramFilesDir"
That value is on every OS.
|
|
|
|
|
Absolutely not. Use the APIs for getting folder paths, they were written to insulate programs from changes in where the OS keeps folder paths (who knows where they're going to be held in Longhorn, for example...)
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
When I convert mp3 to ogg files on the command promt I use a pipe like this:
"lame --decode abc.mp3 - | oggenc -o abcogg -"
I can't use a regular ShellEx function to do this in a program of my own; because the pipe will be sent as an argument to lame. How do I do this. I've tried starting two processes and redirecting their output and input, but I can't make it work.
|
|
|
|
|
Maybe the simplest way is to issue this command via the system function.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
What do you mean by the system function?
|
|
|
|
|
A function called system which is available by including the <stdlib.h> header.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
HI,
Wt are smart pointers and y we use them ?
thanx
Regards.
|
|
|
|
|
Hello Zahid,
Smart Pointers are actually objects which wrap around actual memory pointers. These memory pointers usually point to objects which are reference counted.
Smart Pointers are usually bound to these object pointers on construction. During construction, a smart pointer would usually increment the reference count of the pointed-to object. For example
SmartPtr(Interface *& pInterface) :
m_pInterface(pInterface)
{
if (m_pInterface)
{
m_pInterface -> AddRef();
}
}
During destruction, the smart pointer will usually decrement the reference count of pointed-to object. For example :
~SmartPtr()
{
if (m_pInterface)
{
m_pInterface -> Release();
m_pInterface = 0;
}
}
Smart Pointers can also increase the ref count of their internal object pointers when they are assigned to another object. For example :
// Copies and AddRef()'s the interface.
//
SmartPtr& operator=(const SmartPtr& copypointer) throw()
{
if (operator!=(copypointer))
{
Interface* pOldInterface = m_pInterface;
m_pInterface = copypointer.m_pInterface;
if (m_pInterface)
{
m_pInterface -> AddRef();
}
if (pOldInterface)
{
pOldInterface -> Release();
pOldInterface = NULL;
}
}
return *this;
}
It is this automated reference increment and decrement feature of smart pointer objects that make them most useful for keeping the reference count of COM objects (through their interface pointers).
To properly keep track of COM objects (via their interface pointers), AddRef() and Release() calls must tally. Otherwise there will be reference undercount (leading to crashes) and reference overcount (leading to memory leaks). This is precisely what Smart Pointers are designed to overcome.
There are many more useful functionalities behind Smart Pointers. Lookup the definition of _com_ptr_t in MSDN.
Regards,
Bio.
|
|
|
|
|
|
There are methods to change the pointer shape, why not just create a one pixel mouse pointer and use that ?
Elaine
The tigress is here
|
|
|
|
|
Use the ShowCursor function. Despite its name, it can hide and show the cursor.
|
|
|
|