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

You failed to say what the problem is, but if you want to read one column at a time then using the extraction operator like that won't work right with csv files because columna may, or may not, be separated by white space (spaces and/or tabs). The csv files I've worked with had a comma between each column. So you would probably want to use the getline() function so that you can specify the character that terminates a word.

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

if that first loop is trying to count the number of words in the file, it won't work because words can be separated by one or more spaces or tabs. You don't need to count the number of words anyway. just change the second loop to read until fscanf() returns 0.

while( fscanf( fp1,"%s",text) > 0)
{
   // code here
}

also your program needs to close the file handles after finished reading the file.

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

If you don't want it to exit then what do you want it to do ? you can create a loop as below, but the problem with this is that there is no way to quit the program when you want it to.

int main(void)
{
   while(1)
   {
        printf("hello, world\n");

        fflush(stdout);
        getchar();
    }
}

Another method is to ask to enter 'Q' to quit

int main(void)
{
   int key;
   while(1)
   {
        printf("Enter 'Q' to quit");
        printf("hello, world\n");

        fflush(stdout);
        key = getchar();
        if(key == 'Q')
            break;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
scanf("%c",&words[i]);}
    atoi(&words[i]);}

above is useless. just input the text as normal characters. You don't have to do any conversion at all to get the ascii value of the characters -- data type char already contains the ascii value. To see if its odd or even

// get string from keyboard
fgets(words,sizeof(words),stdin);
//
for(int i = 0; words[i]; i++)
{
   if( (words[i] % 2) == 0)
   {
       // even ascii code
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it isn't necessary to call srand() more than once during the lifetime of a program. The only way to generate an array of unique random numbers is to generate a random number then search the array to see if it has already been generated. If it has, then generate another random number and search again (as in your example program). calling srand() frequently will not help with this.

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

From what I remember from my ancient times is you need to #define UNICODE 1 (but that seems to have already been done !)

Yup -- like me, you too are outdated and nearly obsolete. :)

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

first you need to post the code you have already written. The answer to your question depends on what kind of strings you are using -- std::string class or character arrays ?

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

First you need to learn how to properly format your program -- that is one of the sloppiest format methods I've seen in a long time. Here is an example Notice that you should use spaces very plentifully to make your program easier to read. Curly braces go on a line all by themselves to make them easy to find and match up.

And ust int main() -- never ever void main().

int main()
{ 
    for(int i=0; i <= 100; i++)
    {
        int a[10];
        for (int j=0;j<=10;j++)
       { 
           a[j] = rand() % 10;
          cout << a[j];
       }
    }
    return 0;
}

Now for your question: after generating a random number you need to search the array to see if it already exists. If it does, then generate another random number. You will probably want to put that into another function because you have to use it for several arrays.

int generate(int maxvalue, int array[], int arraySize)
{
   // put your code here which loop that generates
   // a random number and search the array 
   // for existance.  

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

You didn't say which version of VC++ compiler you are using. VC++ 6.0 and VC++ 2005 set UNICODE differently.

VC++ 2005: select menu Project --> Properties . Expand the Configuration Properties folder then select General category. Now on the right side see "Character Set" and change it to "Not Set".

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

sorry, but I am affraid this damn code is from link you just gave me...

Is there any good book?

The code in that link is perfect -- billions of people (:eek: ) have used it.

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

>>The struct date is the same one available in dos.h
that file is not supported by most compilers so we don't have any clue what the structure looks like. But I assume the day, month, and year are integers.

>>Isnt the writing of classes,having character arrays and a structure,to files allowed??
Yes, of course it is. But you have to be carefule that they do not contain pointers. You might also have to consider the packing factor set by your compiler. Packing is usually not a problem until binary files are read by programs created with different compilers.

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

what does struct date look like?

>>fout.write((char *)(&m),sizeof(m));
you really should not write c++ classes to the file like that. classes which contains other c++ classes such as std::string, std::vector, c-pointers, etc, can not be written like that. It is safer and more portable from one run of the application program to another to write out the individual members of the class individually.

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

>>But it looks like its not portable
Of course not -- its only for MS-Windows :)

Tutorial here

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

line 11 may or may not work even though it would appear to us that it should. The reason is because many floats can not be represented exactly in memory due to the way IEEE math works. The best you can do is check for a range of values instead of an exact value.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while (datafile)
    {
        datafile >> row >> col;
    }
    if ( row>=0 && row<Size && col>=0 && col<Size)  // if legal row-col
      Grid[row][col] = true;

In the above code you need to move that if statement to be within the while statement. As it is, your program reads the whole file but does nothing with the numbers.

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

replace the 6 with a star then put the variable in the parameter list

sprintf(blah, "%c%-.*s%c", QUOT, 6, varName, QUOT)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might be able to get it on DVD or CD for $10.00 or so if you look on M$ site.

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

it doesn't sort because you commented that line out in main(). And what is all that crap at the beginning of every line that you posted? I hope you didn't put that there intentially :eek:

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

sometimes professors make mistakes too.

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

you forgot the void function return type

void selectionSort (vector<int>& list, size_t length)

depending on what compiler you are using you may also have to redefine length as size_t instead of int.

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

you need to pass the vector by reference, not by value. like this: void fillArray(vector<int>& list, int length) [edit] Sorry Joe, I didn't see your post before I posted mine [/edit]

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

The code contains an error -- it accesses an element of the array that does not exist, which probably explains why one of the results is 0 instead of 7.

Anyway, the reason for the strange arrangement of the final results is that the function only sorts part of the array. A complete bubble sort algorithm requires two loops, not one.

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

Here is one tutorial to get you started. If your intent is to write games then you should probably use one of the graphics engines, such as DirectX SDK which is free for download from Microsoft.

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

>>Sorry, I am not that advanced and do not know how to note if a string is an empty one or not.

a string is empty when any one of these conditions exist.

inputStr == "";

or

inputStr.length() == 0

or
inputStr.size() == 0

as for multiple blank lines -- it doesn't matter how many blank lines there are, just set the flag to true each time a blank line is detected.

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

I would use a flag to indicate the end of a paragraph -- the first blank line is the end of the paragraph. When the flag then indent the next non-blank line and reset the flag to false.

The while loop is better written like this

while( getline(inFile,inputStr) )
{
    if ( <flag is set> )
     {
       outFile << "     " << inputStr << endl;
       <set flag to false>
     }
    else
     {
       outFile << inputStr << endl;
       <if inputStr is an empty string set flag to true >
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

windows.h contains all the functions you will need for win32 api programs. If you have used functions in graphics.h, then forget everything you learned because ms-windows programming is completly different.

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

you don't need the check for isalph on line 4 -- it really servers no purpose.

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

You must have another function in your program called GetComputerName(). Your code snippet compiled without error in a simple test program that only contains a main() function.

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

you missed my post as well ;)

thanks!

yup, sure did. That's what happens when several people post at nearly the same time.

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

When I compile it, at line 20 I get the following error:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

What am I doing wrong?

you missed my post -- read it again and you will find the answer.

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

you forgot to include <string> header file.

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

you are compiling your program with UNICODE set. Turn UNICODE off by selecting Project --> Properties, Configuration Properties, General, then set the "Character Set" to "Not Set"

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

your code is attempting to open the same file for writing multiple times. You can't do that because the same file can be opened for writing by only one program at a time -- write mode requires exclusive use of the file. What you want to do is create an array of 200 filenames (or however many you want). There are better ways of generating the filenames, but I used this one for simplicity.

char *filenames[] = {
  "patienten/patientent1.txt",
  "patienten/patientent2.txt",
  ...
};

int tel; 
FILE *bestand_patienten[200] = {0};  
for (tel = 0; tel < 200; tel++)
{         
bestand_patienten[tel] = fopen(filenamest[tel], "w");
fprintf (bestand_patienten[tel], "hallo");
 
}

// now close all those files
for (tel = 0; tel < 200; tel++)
{         
   fclose(bestand_patienten[tel]);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well i thought i should create a new array cause i have no idea how i can remove a number from the array using realloc ...

locate the element that contains the value you want removed. Then move all lower elemenets up one place to overwrite that elemement. That will leave the last element of the array unused. Then call realloc() to allocate the array 1 element smaller then it was before.

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

please read through the Read Me posts at the top of this board -- they contain a wealth of information.

Here is a link to good win32 api tutorial

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

I am totally clueless here, so how do i put the x value (width) into x and y value (height) into y
(where x and y are int datatypes)

did you read the link? First create a RECT object and pass a pointer to it to the GetClientRect() function. After that just assign x and y with simple subtraction of the RECT left, right, top and bottom integers. If you can't figure that much out then I doubt your ability to write a program that uses win32 api functions at all. Start with something a lot simpler.

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

GetClientRect() returns a RECT object with the coordinated, then simple subtraction will give you height and width.

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

Thanks for replying. But where's the READ ME?

Look at the top of this page

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

did you read this FAQ and problems thread?

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

test::open() is not the same function as the open function in that unistd.h. If you want to call the function in unistd.h than use the :: namespace operator, for example ::open(/* blabla */); HOWEVER, you are writing a c++ program then use c++ standard fstream objects instead of the very low-level open().

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

TCHAR is just a macro that is defined to be either char* or wchar_t*, depending on whether your program is compiled with UNICODE or not. If not UNICODE then use just simple assignment to convert to std::string. If the program is UNICODE then use one of the conversion functions, such as wcstombs(). That function works ok with English language, but I don't know about other languages.

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

It will work for the arguments you posted, but not for this

c:\myprogram /id TheAdminId /pw TheAdminPw
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

argc is the number of strings in the argv array. argv[0] is always the name of the executable program and will never ever contain a command-line argument.

>>argv + 3
all that does is bypass the first 3 characters of the ith string.

The algorithm you posted doesn't work at all if you put a space between "/id" and whatever is supposed to follow. For example, if you typed this:

c:\myprogram /id something <Enter key>

In the above the program will get two command-line arguments, not one. argv[1] will be "/cd" and argv[2] will be "something". And that will break the algorithm you posted.

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

read the Read Me threads at the top of this board. They are filled with useful FAQ and other links for new want-to-be programmers.

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

your problem is that the program is not aware of the std namespace. You have two choices:
1. after including the header files add this using namespace std; or add std:: in front of each object declaration. std::string filename

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void CFoutTest::print(string text)
{
    fout<<text;
}

Everything compiled ok for me except above in red.

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

>>char b[7]={98,120,97,113,122,121,101},

what is that? If you want to create a char array, do it the normal way so that you don't have to look up those numbers in an ascii table. And you don't have to specify the length unless you want the array to be larger than the initialization string. char b[] = "Hello"; There are a number of C sort algorithms that will sort the array -- the bubble sort is the easiest to code, but also the slowest. It can be coded in about 10 lines of code. Its ok on very small arrays such as what you are using. If you don't know how to code bubble sort just google for it and you will find lots of examples.

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

I don't get any errors or warnings when compiled with my compiler -- VC++ 2005 Pro. Maybe you don't have your project set up correctly. Your code is ok.

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

although Ive opened the file using object.open("") the condition to check that there is indeed an open file always fails and i get my else message "file could not be found"

make sure the file d.txt is in the same directory (folder) as that the executable file is running. If they are not in the same directory then give the full path to the file in the open() function, for example if the file is located in c:\mydir then open the file like this: file.open("c:\\mydir\\d.txt"); the above assumes you are working on MS-Windows, if you are on *nix file.open("/mydir/d.txt");

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

If you are compiling a.cpp what makes you think a.h is not being included?