|
I remember reading through the multi-hundred page MS-DOS 3.3 manual, remembering the commands. I remember reading through the text files on my "teach yourself C" CD with it's Symantec C compiler, and from that made DOS based graphics interface EXE files. I remember learning HTML basics by reading the RFC after downloading them from work ( oh joy, a 2 megabit connection at work in 1998 along with 40 PPM printers ).
All the basics of opening, reading and writing to files, were as valid in C in 1995 as they are today in PHP, but I am continually surprised by the level of some developers I work with. I'm in a PHP house at the moment. They all want to make their own "frameworks", but when it comes to raw language, how to read and write to a file, error handling, bounds checking, loop control (come on now!), the young'uns today seem to have lost the basics. Ok you can build a castle on sand, but don't expect it to last the centures before it falls over. Come on guys. If you are really lost, go bug your local library and borrow somthing written by Donald Knuth along with a language reference. If you cannot solve the problem with that, *then* come here and yell for help!
I don't mind people using the internet to look things up, it's the best reference manual there is today, especially as Einstein is supposed to have said somthing like "the most important is not to know, but to know where to look", but you really have to push this one just a tad further. "Seek and ye shall find", but "understand and ye shall know". This one people tend to forget. I'll help people who help themselves
In the end though, I really get the feeling that I am the last of my species: The self taught geek who relys on his own brain. Oh well. I'll still try to make the most of it while it lasts !!!
Cheers,
Daniel
|
|
|
|
|
Thats really simple stuff that anyone studying a programming course...
Therein lies the issue. When I was in college for my later major, there were people minoring, or auditing programming courses. So they have no real vested interest in programming as a career.
My course featured a beautiful girl who sat next to me, and needed help. That was a fun class. She got help and I got... well, the experience of giving her help, and nothing else.
Still!
It beat the sausage fest' of my physics courses.
|
|
|
|
|
My class also featured a pretty girl. Nearly 45 years later, she's still sitting next to me. Mega-
|
|
|
|
|
That is awesome! Congrats!
|
|
|
|
|
I taught a Digital Logic and Microprocessors class at a local technical college for two semesters back in the mid-eighties. I usually answered a question with a series of questions that I knew the student should know the answer to. In this way I would steer their answers so they would eventually wind up answering their question themselves.
I was fired after two semesters because I wasn't being "helpful" and answering the student's questions. Does that help explain the issue?
modified 27-Apr-12 15:28pm.
|
|
|
|
|
I have created CListCtrl using Create()function. But I dont know to add Message like CLICK, DBILCLK for created control. Friends Kindly help me.
Regards,
S.Shanmugaraja
|
|
|
|
|
Every dynamically created control have an ID, so use that ID and map your event like wizzard do for normal CListCtrl control ...
|
|
|
|
|
Ok, let's do some code sample :
#define IDC_LIST 1001
CListCtrl m_List;
protected:
afx_msg void OnClickList(NMHDR* pNMHDR, LRESULT* pResult);
DECLARE_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CMyClass, CView)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
int CMyClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CView::OnCreate(lpCreateStruct) == -1)return -1;
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | CS_DBLCLKS | LVS_REPORT;
BOOL bResult = m_List.Create(dwStyle,CRect(0,0,0,0),this,IDC_LIST);
return bResult ? 0 : -1;
}
void CMyClass::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
}
|
|
|
|
|
Its working good. In my case control Id is dynamic generated.
For Example:
pmyListCtrl->Create( WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,CRect(10,10,300,200), this, ControlID);
So how can i find controlID? and how to pass this ID into message Map?
|
|
|
|
|
I don't know how you generate dynamic control ID ...
|
|
|
|
|
Simply you cannot have some random IDs for your control but you can have some range of IDs that can be used dynamically, Say from 1001(IDC_MYLIST_START) to 1101 (IDC_MYLIST_END) and use any of this IDs for you list control and make sure you did not have more than one list with the same ID in a given time. For this you have to use ON_NOTIFY_RANGE macro and your message map entry will look like,
ON_NOTIFY_RANGE(NM_CLICK, IDC_MYLIST_START, IDC_MYLIST_END, OnMyListClick)
And you message handler will be,
VOID OnMyListClick(UINT id, NMHDR * pNotifyStruct, LRESULT * result)
The variable "id" will have the list control ID which has been clicked.
Do your Duty and Don't expect the Result
|
|
|
|
|
I'm a total beginner with C++
The program is a calculator written with CodeBlocks
When I compile it CodeBlocks, everything works
but using Visual Studio and Visual Studio Command Line the code seems to be full of errors.
Can someone please assist me what is wrong in the code and how to fix it so that it is compatible with Visual Studio
___________________________________________________
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
// Program discription and Legal Information
cout << ("basic calculator to allow ") << endl;
cout << ("arithmetic operations like +, -, *, / .") << endl;
cout << ("License GPL - by Dominik Schaller - 2012 \n") << endl;
// we need two variables to store the numbers for calculation
float a; // variable a - we use "float" for precission
float b; // variable b - we use "float" for precission
// we need an arithmetic operator for the calculation (+, -, *, /)
string c_operator; // operant input variable as string
// we need a variable to store the result into memory for later console output
float c; // to store the result of arithmetic operation of a and b
// now we enter the first number and store it into memory
cout << ("Enter first number and press [ENTER] to continue\n"); // type number 1
cin >> a; // read number one into variable a
cout << endl; // cleanup
// now we type the operator into the console window as string
cout << ("type operator and press [ENTER] to continue\n"); // type the operator
cin >> c_operator; // read operator as string
cout << endl; // cleanup
// now we enter the second number and store it into memory
cout << ("Enter second number and press [ENTER] to continue\n"); // type number 2
cin >> b; // read number two into variable b
cout << endl; // cleanup
// in this case we use basic if and else staements
// but we also could have used a switch staement
if (c_operator == "+") // check to see if operator is "addition"
{
c = a+b; // if so, calculate (a+b)
}
else if (c_operator == "-") // check to see if operator is "subtraction"
{
c = a-b; // if so, calculate (a-b)
}
else if (c_operator == "*") // check to see if operator is "multiplication"
{
c = a * b; // if so, calculate (a*b)
}
else if (c_operator == "/") // check to see if operator is "division"
{
c = a/b; // if so, calculate (a/b)
}
// now we print the result out to the console screen
cout << ("result is: ") << c << endl; // finally print result on console screen
system ("pause"); // prevent console from shutting down wait...
return 0;
}
____________________________________________________
|
|
|
|
|
You do not explain what errors you get but at a guess it is on the line
string c_operator;
Try adding
#include <string>
in the preamble section of you program.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
aaaaaahh thanks
#include <string>
man.... that solved the problem
at least for compiling on the VC Command line
In Visual Studio (not Express Edition, Student Version), I get this:
2 error LINK1120:1 unresolved externals
1 error LINK2019:unresolved external symbol_WinMain@16 referenced in function__tmainCRTstartup
|
|
|
|
|
You need to change your project type in Visual Studio from "Windows application" to "Console application". The simplest way would be to create a new "Console Application" in Visual Studio and paste your source code into the main source file.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
how i can learn java online . in 20day if i will hard work on that and trully want to learn it how plz reply me
|
|
|
|
|
Asking in the java forum[^] might be a good place to start.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Get a book start learning, if you have any idea about other oop you might be able to do that, otherwise it would be hard i guess
|
|
|
|
|
|
|
Is there a specific way of writing/reading a linked list to and from a random access file in c++....if so could someone please give me an example
|
|
|
|
|
djgmad wrote: Is there a specific way of writing/reading a linked list to and from a random access file in c++....if so could someone please give me an example
In computer science there isn't a standard way of doing much of anything. There is always somebody out there thinking outside the box and doing it completely different.
What you are looking for is called: serialization[^]. For a linked list... just keep in mind that you cannot dump pointers into a file and expect the memory addresses to be valid when you read them back. You could either dump the raw data into a file from memory... or perhaps use a serialization format[^]. There are alot of techniques and different opinions... so you would be well served by using your favorite search engine.
Best Wishes,
-David Delaune
|
|
|
|
|
Hey thanks Mr. David Delaune for your assistance , I've spent the last half an hour or so googling but still hasn't find an example to help...I'm really new to the whole OOP world and C++. Hope I'm not asking for much but is it possible for you to provide some examples please......thanks in advance.
|
|
|
|
|
djgmad wrote: Hope I'm not asking for much but is it possible for you to provide some examples please......thanks in advance.
Sorry I am probably not going to write any code because I don't know what the data in your linked list looks like. It is more work than I am willing to invest to create a serialization class that works for all data/object types. Anyway is the data you want to serialize dynamic in size or static? Does the data contain pointers to other objects in memory? Could you show me what the data looks like?
Best Wishes,
-David Delaune
|
|
|
|
|
You may well be lucky that I can't sleep tonight.
I'm too buggered to provide an overview or description. My efforts in crafting the code carefully are likely to be similarly short-changed..
You should use the debugger to step through the code and a hex-editor to review the created data-file. You'll notice I use (modified) pascal-style strings in the data file since it simplifies loading.
#include <stdio.h>
#include <string.h>
typedef struct node
{
char *text;
int num;
node *next;
};
void addNode(node* &listHead,char *newText, int newInt)
{
node *curPos;
curPos = listHead;
if (curPos == NULL)
{
listHead = new node;
curPos = listHead;
}
else
{
while (curPos->next != NULL)
curPos = curPos->next;
curPos->next = new node;
curPos = curPos->next;
}
curPos->next = NULL;
curPos->num = newInt;
curPos->text = strdup(newText);
}
void dispList(node *firstNode)
{
node *curNode;
curNode = firstNode;
while (curNode != NULL)
{
printf("Text: %s\n", curNode->text);
printf("Num: %d\n", curNode->num);
curNode = curNode->next;
if (curNode)
printf("\n");
}
}
void saveListToFile(node *firstNode, char *szFilename)
{
node *curNode;
FILE *fp;
char asciiNull = 0;
int sLen;
curNode = firstNode;
fp = fopen(szFilename, "wb");
while (curNode != NULL)
{
sLen = strlen(curNode->text);
fwrite(&sLen, sizeof(int), 1, fp);
fwrite(curNode->text, 1, sLen, fp);
fwrite(&curNode->num, sizeof(curNode->num), 1, fp);
curNode = curNode->next;
}
fclose(fp);
}
node *loadListFromFile(char *szFilename)
{
FILE *fp;
node *result = NULL;
char strBuffer[32];
int intBuffer, sLen;
char tmpChar;
fp = fopen(szFilename, "rb");
printf("filePos: %d\n", ftell(fp));
fread(&sLen, sizeof(int), 1, fp);
strBuffer[sLen] = 0;
fread(strBuffer, 1, sLen, fp);
fread(&intBuffer, sizeof(int), 1, fp);
addNode(result, strBuffer, intBuffer);
while (!feof(fp))
{
fread(&sLen, sizeof(int), 1, fp);
strBuffer[sLen] = 0;
fread(strBuffer, 1, sLen, fp);
fread(&intBuffer, sizeof(int), 1, fp);
addNode(result, strBuffer, intBuffer);
}
fclose(fp);
return result;
}
int main()
{
char buffer[32];
int i;
node *listHead, *loadedList;
listHead = NULL;
for (i=0; i<10; i++)
{
sprintf(buffer, "item_%d", i+1);
addNode(listHead, buffer, i+1);
}
saveListToFile(listHead, "list.dat");
loadedList = loadListFromFile("list.dat");
printf("Created list:\n");
dispList(listHead);
printf("Loaded list:\n");
dispList(loadedList);
return 0;
}
|
|
|
|
|