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

your program has corrupted the stack someplace -- most likely buffer overflow or possibly use of uninitialized pointers. Its impossible to diagnose without seeing the entire program. I would probably start debugging by commenting out huge blocks of code until the problem goes away. Then you will know approximately where the problem is.

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

I do similar, but I put that log function in another thread so that it doesn't slow down other processing. you can put the log requests into a queue, then the log function can take its own sweet time processing them. Also, I always close the file when the last item in the queue has been logged.

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

maybe its a virus or something like that?? I have no such file on my computer and I have Visual C++ 2005 Pro and VC++ 6.0 installed. Is your computer setup to be an e-mail server or web server (mine is NOT)? If not, then move the file someplace else and see if that fixes the problem. If it does, then I'd suggest just deleting it.

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

>void main() is never ever acceptable
It's perfectly acceptable on a freestanding implementation. The rules we refer to when talking about main are exclusive to hosted implementations.

what do you mean by "freestanding implenentation"? some embedded systems where there may not even be a main() function ? I doubt there are may people in the whole world who program in that kind of an environment. And I don't think the c standards apply there anyway.

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

If you don't want to return a value in main(), declare main() as void.
void main()

main MUST ALWAYS return an int. void main() is never ever acceptable, even though some ancient compilers such as Borland's Turbo C, might not complain and despite the many examples you will see on MSDN. Current standards require main to return an int, and say it is not necessary to return 0 at the end of main().

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

Yes, it can be done with c++, but it's a pretty complex and very very messy -- see this about Office Automation

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

>> any suggestions

upgrade to Visual C++ 2005 Express

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

why doesn't hw2head.c contain any includes? Add hw2head.h to the top of hw2head.c and that will probably fix all (or most) of the problems.

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

In function input_university() I see where scanf() is reading the string, and univ->std[num_cells].name is getting allocated, but I don't see where it is copying buffer to univ->std[num_cells].name after allocation. Add this and it will probably work ok.

strcpy(univ->std[num_cells].name,buffer);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Visual C++ 1.52, I am trying to teach myself programming

well, you won't learn much by using that ancient compiler, and what you do learn will most likely be wrong. Get yourself a modern compiler -- there are several free ones that are good for learning, such as Dev-C++ from www.bloodshed.net

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

>>any suggestions
1. you can use ODBC, this is the oldest and most popular method of acccessing SQL databases. Just use google and you will find free c++ classes and instructions.

2. review the Enroll tutorial at www.microsoft.com -- it uses MFC which you might or might not want. If not, then use ODBC.

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

well, you might as well post some code that shows how you declared the variables and how they are being used. This guessing game is the pits. If transCode is a single character, then you have to use single quotes. If it is std::string then use double quotes. If it is char* then you use neither -- use strcmp() instead. There are so many possibilities that it isn't possible to give you a straight answer because you didn't provide enough information of show us any useful code.

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

Ok, thanks too -- I guess I just didn't know how to use it.

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

The "Insert Link" button normally presents two dialogs -- one to enter some text and the other for the url. It doesn't do that any more -- only asks for the url. Will you please fix this:?:

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

What compiler/version are you using? I have had warning C4530 with winCE and solved the problem by adding -GX to the compile flags. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=195818&SiteID=1

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

If transCode is of type std::string, then you would use double quotes. The compiler will complain loudly if you use single quotes.
if(transCode == "A")

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

>>// I think clock() is only available for Windows,

clock() does NOT give you current date/time. It will only give you the number of milliseconds since your computer was last booted, or some rollover value.

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

I need to pull the Any Name Here into a variable and then use my usual

the >> insert operator stops reading the keyboard when it encounters the first space. If you want the string to include spaces, then use getlin()

std::string full_name;
getline(cin,full_name);

>> Also if I have an array serviceCounts[j] how do I add one to the j value?

use j++. Either of the two methods below will work.

serviceCounts[i][j];
j++;

or sorthand
 serviceCounts[i][j++];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in MS-Windows you can call win32 api function GetSystemTime() that returns a SYSTEMTIME structure. Other operating systems probably have something similar, but I don't know what they would be.

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

Good work! you get an A for the day :)

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

>>Bench is right. You are reading past the EOF.

That's what I said in my original post -- that loop will not work the way it is coded. If some people (OP) would learn to read :rolleyes:

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

One problem is that you are attempting to open the same file twice -- once in main() and again in Checkfile(). After opening the file in main() just pass the ifstream object to Checkfile.

while (!openfile.eof() && Record < ArrayRecord && !openfile.fail())
     {  
         //While loop, As long as the statement not equal to end of file,
         //record is lesser then ArrayRecord, and opening file does not fail
         //Then perform the following.
          
          openfile >> CustID[Record];

Above is incorrect way to write that loop -- ifstream returns null on eof.

while (Record < ArrayRecord && openfile >> CustID[Record] )
     {  
         //While loop, As long as the statement not equal to end of file,
         //record is lesser then ArrayRecord, and opening file does not fail
         //Then perform the following.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

MS-DOS became extinct after version 6.X. If you have MS-Windows installed on your computer than you do NOT have MS-DOS. You probably mean a command-line window, which is an MS-DOS emulator

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

I don't know what code you are talking about that is in turkish -- that other thread contains no such code. If you are turkish_girl then why can't you read it? Post the code you have (in English please) and we'll try to help you out. I know all about those looooong hours, that's just the nature of the beast.

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

Yeah i know how to use rand() and the only thing about reading it in to figure out the size.... if i know its 50 lines... can't i just set that part of the array to 50 and for rand() just do the rand(( % 50) + 1) type thing?

Yes you could do that, but then what happens when you choose a different file with a different number of lines? In that case you have to recompile your program.

i was referring to the fgets() i never used them in the c++...

Oh, now I understand. C file i/o is a little different. Here is an example, just in case you are confused.

#include <stdio.h>

int main()
{
   // buffer for file i/o
   char buf[255]; // just an arbitrary size here.  I'd rather it be too big than too small.
   // open the file for reading
   FILE* fp = fopen("somefile.txt","r");
   if( fp == NULL)
   {
      printf("Can't open the file\n");
      return 1;
   }
   // read each line of the file
   while( fgets(buf,sizeof(buf),1,fp) != NULL)
   {
      // count the lines or do other stuff here
   }
   // close the file
   fclose(fp);
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you bother reading this thread ? Its nearly identical assignment -- in fact that poster could also be in your class!

I have already done that assignment in C and C++, but I'm not about to post the results -- wouldn't want to spoil your fun :mrgreen: I did both programs the way I explained in the other thread.

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

i appreciate the reply.

Yes, i was gonna use the rand() function like you suggested. But for the fgets.... Reading the whole file first using them, then re-reading the file? I dont understand that. What does the first reading do exactly if you are going to reread it?

The first reading is to count the number of lines in the file so that you can limit the range of numbers returned by rand(). The second reading is to access a specific line number. Two readings are necessary when the file is too large to fit in memory all at one time.

As for the memory, the file would be about 50 lines. And at the end, if you do a rand() and it is 5... it would read the first 5 lines using an fget() (i get that) but would it output all 5 with an fget()? because I would only want that fifth line.

With a file that small, just read the whole thing into an array -- again you need all for the same reason as above -- so you can limit the return value of rand(). If the file has 50 lines you don't want rand() to give you a number of 1,000!

NOTE:
I learned C++ and can handle the pointers and everything, but these new functions im not used to in C are kind of a pain!

All those functions are standard C. There is nothing that is not part of ansi …

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

fstats[index value]++, now i'm just using pointers how would i do this??

I thought *(fstats +1)++ would increment the second position of fstats array because fstats points to the first postion but syntax wise this does not work. I am currently placing the certain index value accrodingly, kinda like cheating. How can i do this with just pointers like fstats +1...fstats+5 and so on, want to increment the value by one in each index accordingly

I do it the same way you did before -- just because the array is allocated dynamically doesn't mean you have to learn different pointer operations

fstats[index value]++;

But if you really want to do it differently, here is one way

int main(int argc, char* argv[])
{
    int i;
    float* array = (float*)malloc(10 * sizeof(float));
    for(i = 0; i < 10; i++)
        array[i] = 0;

    for(i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            (*(array+i))++;
        }
    }

    for(i = 0; i < 10; i++)
        printf("array[%d] = %f\n",i, *(array+i));

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

there are at least a couple ways you can approach the problem.
1. Read the whole file into an array as you posted. Then generate a random number between 0 and the number of lines read -- see rand() function. That can take a lot of memory if the file is really huge. If you have learned about pointers, then you would want an array of pointers, so that the memory for the lines can be allocated to the exact length of the lines

2. Don't read all of it into memory -- leave it on the hard drive. When the program starts, loop though the file using fgets() and count the number of lines in the file. Generate a random number as #1 above, rewind the file, and re-read using fgets() until the line number has been read. Example: the file contains 50 lines, generate a random number between 0 and 50, lets say 5, then read the first five lines.

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

try google

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

Here is the version of ACE_WString whose second constructor takes char*. I have no way of knowing if that's the same one you are using.

QString has two methods that you may be interested in -- ascii() that returns char*, and unicode() that appears to make the ascii to unicode conversion for you.

QString str = "Hello";
ACE_WString w(str.ascii());

I'm just sort of guessing about the above because I don't have either of those classes.

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

that was as specific as I'm going to get without actually coding the program for you.

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

I really don't know the answer, but I would start here

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

where is the c/c++ programming question?

Did you check to see if the caps lock key is on :rolleyes:

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

I don't know why you are using those odd-ball, non-standard c++ classes, maybe the university requires them? But anyway, looks like ACE_WString has a constructor that takes const char*, so just pass the right QString method that makes that conversion for you. You'll have to look it up.

QString str = "Hello World";
ACE_WString wstring(str.??());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use a data file that contains lots of words -- for example (USA) President's Lincoln's Gettysburge Address (you can use google to find it) or some other file you may already have on your computer. Read the file one word at a time, keep track of the total number of characters read (plus 1 for at least one space between words). When that sum >= 80 (or whatever number you choose) you know the last word read will not fint on the current line, so output all words and spaces read so far. You will have to use an array to hold the words that have been previously read.

Before you output the words, sum total length of the characters and substract from total desired line length. For example, if sum = 70 then 80 - 70 = 10. You will have to distribute 10 spaces between the words. If there are 6 words, then there will be 10/6 = 1 space between words, plus 4 spaces you will have to distribute between the first 4 words. So the first 4 words will have 2 spaces between them and the last 2 words will have only 1 space.

Once the number of spaces between words is derived the function can start outputting the line. start a loop

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

first find out how many words are on the line, count the length of all the words. subtract that from the total line length and you get the number of spaces that you have to distribute between the words. divide that number by the number of words and you get the number of spaces you have to put between each word.

Example
"any text abouth 900 characters"
That contains 27 characters, not counting the spaces. If you want a line length of 40, you get (40 - 27) = 13 spaces that have to be distributed between the 5 words. Because there are no spaces after the last word, the 13 spaces have to be distributed over 4 areas, or 3 spaces between each word with 4 spaces between the last two words. That makes the final string look like this:

"any   text   abouth   900    characters"
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use the chdir() function instead of the system() because (1) its faster and (2) its safer

chdir("c:\\");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what keyboard language is installed on your computer? UK and American keyboards are different scancodes for the same key. American keyboard prints '#' for the Shift-3 key, while UK prints ' £'

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

can u sugegst me the coding in "C/C++" to read this file which will save file in text format or any other format ., then we will able to convert in required database.

thank u

Well, you could use ODBC to read the tables using normal SQL statements. There are ODBC c++ classes on the net, just google for them. You can have two databases open at the same time each with its own connection. Get a resultset from one db then use sql statements to insert the rows into the second db. That should be pretty straight forward, and you don't have to know a thing about how the files are maintained. Buy yourself an SQL book if you don't know the langage -- its too complex to explain here.

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

the header file is incomplete. you probably didn't post the whole thing.

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

Hurray! The link worked. Thanks :)

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

you forgot to block in the code for the last if statement.

if (StrokeCount > 5 ) 
             { 
			    
					Par = StrokeCount%5;
				
				cout <<" You are "<< Par <<" over Par" << endl;	
				cout << endl;
             }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while(input_file.getline(line, sizeof(line), '\n')) // to read lines
{

linecol = line;
while(linecol != "")
{

int pos = linecol.find(',');
field = linecol.left(pos);
,,,

std::string.substr(...) is similar to QString's mid method.
http://doc.trolltech.com/3.3/qstring.html

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

>>string[strlen(string)] = '\0';

That may or may not work -- if the string does not contain '\n' the above will cut off the last character that was read. fgets() appends the '\n' ONLY if there is one in the stream -- for example if the buffer is filled up before reaching end-of-line or when the last line in the file does not contain '\n'. So the safest way to do it is to check if the last character is '\n'

int len = strlen(string) -1;
if( string[len] == '\n')
   string[len] = '\0';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you forgot to include the header file in the *.cpp file. You may also need other header files too, such as iostream, fstream, string, etc. depending on your code.

#include "dateSType.h"
// rest of cpp code here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> VC++
That is the name of a specific compiler, not c programming language. Of course it supports c++, vector and push_back. You are writing a c++ program, if you want to use vector c++ class as I illustrated you have to include <vector> header file.

>>QString linecol
QString is a non-standard c++ class that M$ apparently developed for their compilers. I haven't used managed c++. the strings I posted are std::string from <string> header file, and maybe that is why you couldn't get it to work.

>> matrix_points[r][c] = line;

I mentioned this before -- you can't do this because matric_points is a 2d array of characters, not a 2d array of pointers

char *matrix_points[255][255]; // 2d array of pointers

matrix_points[r][c] = new char[strlen(line)+1];
strcpy(matrix_points[r][c], line);
while(input_file.getline(line, sizeof(line), '\n')) // to read lines
{
while(line != "")

how is line declared? if it is a char array, then the code above will not work. If it is QString or std::string it still will not work. You are mixing c and c++ -- attempting to use c++ techniques on C string, or attempting to use C techniques on C++ string class. But I don't know which it is because you didn't post enough code.

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

If you can't access the site from one browser but you can from another on the same machine.

The IE6 is at work and FireFox is at home, about 20 miles away in a different city. I'm in Illinois and will try again this morning when I get to work.

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

The code I posted will still work, just replace the space in find() with a comma

int pos = line.find(',');
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how long is this going to go on anyway? I still cannot access it from IE6 -- Firefox works ok.