Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. Hope to see you around in the Software Development board and probably Geek's Lounge.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is an ancient 11-year-old compiler (released in 1997) that does not support c++ very well. You should probably upgrade to the most recent compiler anyway.

BTW: I don't know how to fix your problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>[EDIT] Re-reading the OP's original post, do you mean to say that pressing Alt-Enter in the command prompt doesn't switch you to a pure text-mode on the monitor?

This is what you see on Vista when Alt+Enter is pressed.

DOSBox link

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>FindFirstFileW' : cannot convert parameter 1 from 'const char [6]' to 'LPCWSTR'
That errror means you are compiling your program for UNICODE, which is the default setting for VC++ 2005/2008 compilers. If you don't care about languages other than English you can turn UNICODE off.
Project --> Properties --> Configuration Properties --> General. On the right side of the screen change "Character Set" (third item up from the bottom) to "Not Set".

There is an extensive example of how to use FindFirstFile() in the code snippets. But it might be a little too advanced for you. The first parameter is the path and files that you want to start the search. For example if you want all the *.txt files in c:\MyDirectory then the first paramter would be "c:\\MyDirectory\\*.txt". The second parameter is a pointer to your WIN32_FIND_DATA object.

WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile("c:\\MyDirectory\\*.txt", &FiundFileData);
if( hFind != INVALID_HANDLE_VALUE)
{
    do {
           // save this file name
    } while( FindNextFile(hFind, &FindFileData) );
    FindClose(hFind);
}

Note that the above will not process any subdirectories unless the directory name has a *.txt extension (which is probably very very unlikely)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want a random-access file where you can go to any record without reading all the intermediate records then the file must be in binary form with fixed-length records. Your class ClientData makes that pretty easy to implement because of its fixed-length data objects.

You have to open the files in binary mode using ios::binary flag ofstream out("filename",ios:binary); then use the ofstream's write() function to write out one record. So lets say you need to rewrite the 10th record

#include <fstream>
using namespace std;
int main()
{
    ClassData obj;
    ofstream out("filename", ios::out | ios::binary);
    // seek to the 10th record
    out.seekp(10 * sizeof(ClassData));
    // write the 10th record
    out.write(&obj, sizeof(ClassData));
}

Similar code as above to read the 10th record (or any record in the file)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean this: I'm using Vista Home Premium

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No I just want to make a C Simple Program using interrupts or bios services

Not in MS-Windows or *nix you won't because the operating systems will not allow it. You might, however, use an old MS-DOS compiler such as TurboC with inline assembly code, but you will probably have problems with today's huge hard drives.

There is no simple solution to your problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I thought you were asking how to do that in a C program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Huckabee seems to be a very nice kind person, one whom I'd love to have as a neighbor. But President -- no. We had one president during my lifetime that was a devout Christian (Carter) and he didn't make a very good president either.

joshSCH commented: I do agree +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's the correction

int main()
{
   HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
COORD NEW=GetLargestConsoleWindowSize(hStdout);
printf("%d\n",NEW.X);
printf("%d\n",NEW.Y);

    
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm pretty sure you will have to write kernel-level program to do that. Here is a tutorial to help get started with the Windows DDK

IOCTL is another possibility

SpS commented: Nice Link +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well i have requirements to follow but it doesn't say i can't use an array but I'm sure it has to be something we covered in class and i don't think std::string word is something we covered.

If you have not covered std::string yet then replace it with a simple char array

char word[40];
while( inFile >> word )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well in that case you need to use the answer in the open statement instead of hardcoding the filename. line 19 should be this: inFile.open ( cloze );

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 30: why is that a double instead of an int ? Do exam IDs contain decimal places ?

line 39: assert does nothing if the program is not compiled for debug. And it does not stop the program if the file fails to open. In otherwords, its not useful for what you are trying to use it for. Instead you should test for valid opening

if( !infile.is_open())
{
   cout << "File not opened\n";
   return 1; // don't continue the program
}

line 48: I don't know what you want to do in that switch statement.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Tutorial

Learn to use google and you will get the answers a lot faster.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to use win32 api console functions which you can not do with Turbo C or TC++ because that compiler is too old.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are going to hardcode the filename then there is no point in lines 14, 15 and 16, so you might as well delete them.

>>also is that what is called using an array??
No. Nothing I posted uses an array. I see no reason to use an array in this program, unless there is some requirements that you didn't post.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. The second parameter is not a filename, but a structure that contains a lot of fields including the filename. Look up FindFirstFile() in MSDN and you will see that that structure contains.

2. FindFirstFile returns a HANDLE. Setting this->textBox1->Text = h is just flat wrong. you should be setting it to the char array filename thats in the structure.

If you search the code snippets you will find a couple very extensive programs that use FindFirstFile() and FindNextFile().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm probably not the best person to answer your question because I have used boost very little.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ok, you're right it is cloze -- my bad. I should have looked it up before critizing you for that.

Back to your problem: lines 23 thru 35 are all wrong. You want to read the file one word at a time, not one character at a time. The >> operator will do that very easily

std::string word;
while(inFile >> word)
{
    cout << word << " ";
}

now after the above finished just rewring the file using seekp() then clear all errors and read it the second time with the replacements you have to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's another way to use a vector of function pointers. This uses c-style function pointers, and this could probably be simplified too.

#include <iostream>
#include <vector>
using namespace std;



int a(float x, char b, char c)
{
    cout << "function a\n";
    return 1;
}

int b(float x, char b, char c)
{
    cout << "function b\n";
    return 1;
}
typedef struct
{
    int (*fnptr)(float, char, char);
}Callback;


int main()
{
    Callback fn;
    vector<Callback> FCallBack;
    fn.fnptr = a;
    FCallBack.push_back(fn);
    fn.fnptr = b;
    FCallBack.push_back(fn);
    vector<Callback>::iterator it;
    for(it = FCallBack.begin(); it != FCallBack.end(); it++)
    {
        Callback& cb = *it;
        cb.fnptr(0,'A','B');
    }
    
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what do you mean by "cloze <sinc> test" ? BTW: its spelled close not cloze. Do you mean to close the file and reopen it for the second reading?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It's supposed to be a cloze test...
Doesn't that mean you're supposed to write the program without help from anyone? If yes, then isn't asking us for help the same as cheating by looking in your textbook?

line 19: why is the filename hardcoded instead of using the name you have to type at line 15?

delete lines 20 and 21 because that's the default behavior when a file is opened.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably somewhere in Web Development, or if you are using PHP you could post in Software Development.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If I had all the money in the world -- I'd give it away to everyone that wants it. But I'd have to be very careful about that too because it could cause a surge in the inflation rate. If I gave everyone a million dollors (pounds, or whatever currency you like) then it might cost a thousand dollars for a gallon of gas or an apple. If I invested it in the stock market then the price of stocks would skyrocket. The only way to avoid high world-wide inflation rates with that much money is to hide it under my mattress and not spend any of it. In that case what good would it be ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it annoys me as im subscrive to over 100 pages worth of threads so i cant unsubscribe by ticking each page - unsubscribe all would be nice

sorry for the hijack ;)

Yes I agree -- I experience the same problem a couple years ago when I was subscribed to over 300 threads. The only way to unsubscribe was to do it one page at a time -- what a pain in the ass that was! I have since turned off subscribing to threads.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a version that doesn't crash when ran. I completly replaced your read_word() function to use fscanf() -- its a lot easier when just reading space-deliminated words from a file.

The program does not meet all the requirements, but at least it doesn't crash.

#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996)

#define ch_limit 500

struct node {
	char word[ch_limit];
	int count;
	struct node *next;
};

typedef struct node *list;

int count_lines(FILE *fp)
{
return 0;
}

list populate(char *word,list first)
{
        list temp = NULL, node = NULL;
        int value=0;
        temp=(list)malloc(sizeof(struct node));
        memset(temp,0,sizeof(struct node));
        strcpy(temp->word,word);
        temp->count=0;
        temp->next=NULL;

        
        if(first==NULL){
                return temp;
        }
        node = first;
        while(node->next!=NULL){
                if(strcmp(node->word,word)==0){
                        node->count++;
                        free(temp);
                        return first;
                }else{
                        //printf("I am inside\n");
                        node = node->next;
                }
        }
        if(strcmp(node->word,word)==0){
                node->count++;
                free(temp);
                return(first);
        }
        node->next=temp;
        return(first);
}
list read_word(FILE *input_file)
{
    char word[ch_limit] = {0};
	list first=NULL;
    while( fscanf(input_file, "%s", word) > 0 )
    {
			first=populate(word,first);	
    }
    return first;
}
/*
list read_word(FILE *input_file)
{
	char word[ch_limit];
	int ch;
	int i,count=0;
	list first=NULL;
	
	while((ch=fgetc(input_file)) !=EOF){
		
		for(i=0;(ch!=' ') || (ch!='\n');i++){
			word[i]=ch;
			ch=fgetc(input_file);
			if (ch == EOF)
				break;
		}
			word[i]='\0';
			first=populate(word,first);	
			
	}
	return(first);
}
*/

void display(list first,int line_nos)
{
	list unique,common;
	common=unique=first;
	if(unique==NULL){
		printf("The list of unique words is empty\n");
		return;
	}
	printf("Unique List: ");
	while(unique){
		puts(unique->word);
		printf(" ");
		unique=unique->next;
	}
	printf("\n");

	if(common==NULL){
		printf("The list of common words is empty\n");
		return;
	}

	printf("Common List: ");
	while(common){
		if(common->count!=line_nos){
			puts(common->word);
			printf(" ");
		}
		common=common->next;
	}
	return;	
}


int main(int argc, char *argv[])
{
	FILE *input_file;
	int line_nos;
	list first=NULL; …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I tried to compile it with VC++ 2008 Express and got a lot of warnings. Most of them were about functions that are declared to return an int but return nothing. You should either add return a number or make the functions void.

line 21: you are allocating too little space. list is a pointer and what you want is the size of the struct node. replace list with struct node


line 33: strcmp() does not return NULL -- it returns 0. VOID may or may not be defined as 0, depending on your compiler. strcmp() returns an integer.

line 130: close() is undefined. You probably meant fclose()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I like my 19" flat-screen monitor because it doesn't take up much desktop room.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

so do the people im talking about ,I can't explain it !!

They could be running with out-of-date virus database, or ignoring the warnings they will get when downloading something or visiting bad web sites such as porn sites. A lot of stuff you download from university sites also contains viruses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use Access (or any other database) you will have to lean SQL query language and one of the many programming languages that can access the database, such as VB, C#, C and C++. Using Excell you don't have to know anything about any of that. So your choice will depend on how well you know Excell and database languages.

Word of warning: If you elect the database route and write computer programs for it then you should add copyright notices at the top of every source code file. Its important that you retain the copyright of everything you write even if someone pays you to write it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've tried Norton, McAffee and Avast 4.7. I hate McAfee because the buttons are not visible with the somewhat low display resolution that I use, so I tossed it into the bit bucket. I sent them an email about it but never got a response. Norton worked ok, but required annual support fees. Avast is what I use now and I think it works as well as Norton and is free for home use, and I get free updates several times a week.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how many times in your life did you have to reinstall windows?

My life spans 65 years, so its quite a few times. When I was using MS-DOS 6.X I had to reinstall it probably every week or so because my programs would easily trash the file system. Along came Win95, and I would reinstall maybe monthly for the same reason -- trashed file system. Each succeeding version of Windows brought better and more secure file systems. I have not had to reinstall Windows at all since W2K. I have reinstalled a time or two over the past 5 years just to upgrade the hard drives. I always run anti-virus programs so I've never had to reinstall due to viruses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Complex numbers are supported.
http://books.google.com/books?id=Nfh5-L3NBTQC&pg=PA67&lpg=PA67&dq=c+from+novice+to+professional+complex&source=web&ots=Ny0_1k8kse&sig=_afZdiOLhi6B3iLfyisPDdCwNUw

From what I understand here the _Complex keyword was added in ISO C99 and is probably not implemented by very many, if any, compilers on the market today.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First I would create an array of valid month names, such as

string months[] = {"January","February","March" ... };

Then after the user enter the month name just create a loop and compare them

int i;
for(i = 0; i < 12; i++)
{
   if( month_name == months[i] )
   {
        // found it
   }
}

After the above is complete, the value of the i counter is the month number that you can use in that switch statement

switch(i)
{
    case 0: // January
    case 2: // march
         days = 31;
   // etc.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> while (difference >= (1 * (10 ^ -4)));

Is that try to raise 10 to a negative power ? Doesn't that produce an imaginary number (which are not supported by C or C++ native languages)

You might want to check out some of the boost library math function

[edit]I checked with google and found that negative exponents don't do what I thought. So just ignore my dumb question above. See -- I said I was math impaired :) [/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
1>c:\documents and settings\myfolder\desktop\mydocs\c\visual\memory\memory.cpp(57) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

That is a Microsoft-Specific warning message. M$ doesn't like using the standard C style string functions like strlen(), strcpy() etc because they have potential problems of overwriting buffers, which is true because they are dangerous if extra care isn't taken to insure program safety.

If you use the replacement function identified in the warning message then your program will not be able to be compiled by other programs because those replacement functions are not standard functions. If you have to hand in the source code of your assignment to your teacher, then your teacher can't compile it without using the same version of the Microsoft compiler that you used.

My suggestion to students is to ignore that warning message and use #pragma warning(disable: 4996) to prevent the compiler from issuing it -- unless of course your teacher has instructed you to do otherwise.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just delete line 4, 5 and 6 because it is defined in windows.h (wincon.h)

>>printf("%d",x.WINAPI);
what is x.WINAPI?

>>Please advice what is wrong with the syntax
Everything. WINAPI is not a data object that can be printed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> there are no errors when i compile, but the program still doesnt work properly, grrr. frustating.
Welcome to the wounderful world of computer programming ;) Sorry that I can't help you -- the math is beyond me.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

VC++ 6.0 will work on Vista but you will get a lot of compatability warning messages. VC++ 2008 Express runs perfectly on Vista. So if you are currently using VC++ 6.0 you should upgrade to VC++ 2008.

I use Dev-C++ on Vista. But you may have to add full paths to the directories listed in in Tools --> Compiler Options --> Directories.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ps. #include <iostream> when using cout
You are right -- I forgot that I had it in stdafx.h

There are just too many ifs about the OPs problem for us to be of much help.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you mean an array of strings or an array of chars = (sort of)string
so : string str[x] or char str[x]?

From w_char to string:

#include <sstream>

[....]
stringstream ss;
ss << ffd.cFileName;
string str;
ss >> str;

Let me know if it works

Niek

That doesn't work when the program is compiled for UNICODE. It will compile, but just produces garbage at runtime.

#include <sstream>
#include <string>
#include <windows.h>
using namespace std;

int main()
{
TCHAR cFileName[] = TEXT("Hello World");
stringstream ss;
ss << cFileName;
string str;
ss >> str;

cout << str << "\n";
return 0;
}

Now compile and run the above with UNICODE enabled.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>str[0] =ffd.cFileName;
It depends on how str was declared. Is it char str[ <some number here] or like this: TCHAR str[ <some number here> ] It also depends on whether the program is being compiled with UNICODE or not. If you declared str using TCHAR then you could call _tstrcpy() and let the compiler figure out how to make the conversion. _tstrcpy( str, ffd.cFileName);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 16: variable a is NOT a string but just an array of characters because it is not null terminated. So string functions such as strlen() (line 18) and cout (line 29)will not work with it. To use strlen() you should have declared it like this: char a[] = "tanka"; array b also needs to be increased by 1 to hold the null terminator character and it should be declared like this: char b[6] = {0}; line 20: array b doesn't contain anything at that point so why are you adding it to the vector? And since b has not been initialized to anything it will cause the vector a lot of problems, possibly even crashing your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean no computer ??

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Can Fly() be called that many times per second ? What will happen if that function is called again before it finishes the first time?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

McCain is just too blasted old to be President, if elected the chances are very good that he won't live his 4-year term. He should be in a nursing home with lots of pretty nurses not in the WH.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a list of all the console functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is a ridiculously pointless thread..

Not really -- most knives have points that are pretty dangerous :)

joshSCH commented: Clever ;-) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

LOL.. Great thread ! I think it should be bookmarked. *Tips to find a girlfriend* ! :P

Oh! So, is this the way you find girlfriends in India too :-O I thought you were much more reserved and old-fashioned, meaning getting introduced to GF by a family member.