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

I already told you with the code I posted above. It does exactly what you are asking. I just put the numbers in an array of integers rather than in individual variables. Just put the code I gave you in a loop that uses fgets() to read the file one line at a time, so that you know the begenning of each line.

Or if you know there will always be 4 numbers on each line and that it will never ever be anything else

int userID;
int time;
int from;
int to;
FILE*fp = fopen("filename.txt","r");
while( fscanf(fp,"%d%d%d%d", &userID,&time,&from,&to) > 0)
{
   // do something with the data
}
fclose(fp);
SamSmiles commented: Was very nice and helpful +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Standard i/o stuff -- read the file from beginning to end until you find the line you want. This is a first year programming question, are you sure you are ready to write MFC programs?

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

You might find examples in one or more of these google links

Epecially read this article

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

use fgets() to read a line, then for each line you can use strtok() to tokenize it, then atol() to convert from char* to int.

Another way is to use strtol() in a loop. Example

int main()
{
    char line[] = "12 23 34 45";
    char* ptr;
    int n1[4];
    int i;
    i = 0;
    ptr = line;
    while(*ptr != '\0' && (n1[i] = strtol(ptr,&ptr,10)) < LONG_MAX )
    {
        printf("%d\n", n1[i]);
        i++;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Try the following one:
taskkill /f /im explorer.exe

Why don't you read the posts in this thread??? That has already been suggested by someone else. You mearly parroted what he said.

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

The same way you would do it in a normal c++ program.

#include <vector>

int main()
{
  std::vector<int> array;
}

MFC has a lot of container classes, and depending on what you want to do, they may or may not be better than std::vector or std::list. Your compiler CD/DVD includes hundreds of example programs that show how to use those container classes. Just browse your own computer for them.

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

I like IE8 better.

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

There is no such thing as "Non Ansi C Standard". If its not in the Ansi C Standard then it must be, by definition, non-ansi C.

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

did you declare variable CStr? CString Cstr; Instead of that loop, just try this: CSt = str.c_str(); assuming CStr is of type CString.

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

>>I have tried to tokenize the whole file
Post what you have tried.


>>getline cant have delimiters in it.

std::string word;
ifstream in("filename.txt");
while( getline(in,word,',') )
{
  do something with this token
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to call CreateFile() to open the comm port. Then you use the win32 api Communications Functions

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

>>do I have to redraw everything?
Yes, well maybe.

>>if so, which controls should I include (at WndProc?)
catch the WM_PAINT event.

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

>> How do I edit my profile?

Click the CONTROL PANEL link at the very top right corner of the page. It's just above the SEARCH edit box.

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

Slap your friend across the side of his head and tell him "don't do that!"

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

OMG I hope he is not taking a college course ;)

A better way to write that. Note that you don't need all those C header files.

#include <string>
int main()
{
   for(int i = 0; i < 1000; i++)
   {
      std::cout << i << '\n';       
   }
   std::cin.get();
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

WinZip can not read that *.zip file.

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

Here is one way to prevent duplicates

BTW: assert() does nothing when the program is compiled for release mode instead of debug mode.

void uniquebag::insert(const value_type& entry)
{
	assert(size () < CAPACITY);
    // check if the number already exists in the array
    bool found = false;
    for (size_type i=0; i < used; i++)
    {
        if( data[i] == entry)
        {
            found = true;
            break;
        }
    }
    if( found == false)
    {
	    data[used] = entry;
	    ++used;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is c++ forum, not C.

Here is one way to do it, but I doubt that is that you really want.

int main()
{
   cout << 3 << '\n';
   cout << 323 << '\n';
   cout << 32123 << '\n';
   cout << 323 << '\n';
   cout << 3 << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

CComboBox does not have an items property. (CComboBox*)(GetDlgItem(IDC_COMBO1))->AddString("Text");

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

>>Will this create a suttle memory overrun

Absolutely. sizeof(A) is 1. sizeof(float) is 4. Now you guess the result.

>>B[0] /= 3l

Wrong. It's *B /= 3; because B is NOT a pointer to an array but a pointer to a float. But since A is not a float that code snippet will have dedefined behavior, possibly crashing the program.

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

you have to check for error, and if it occurs clear the input buffer

See this thread about how to clear the input buffer.

#include <iostream>
#include <limits>
using std::cin;
using std::cout;

int main()
{
    int c;
    while(true)
    {
        cout << "Enter a number\n";
        cin >> c;
        if( cin.fail() )
        {
            cout << "Oops!\n";
            cin.clear();
            cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
        }
        else
            break;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Are you sure unions will work well with types of different sizes?
Absolutely yes. That's the purpose of unions. The sizeof(AnyType) is the size of its largest member.

>>Is val.val /= 2 legal
No, but val.val.iVal/2 is legal

int result = 0;
switch(val.type)
{
   case TYPE_INT: result = val.val.iVal/2; break;
   case TYPE_CHAR: result = (int)val.val.cVal/2; break;
   case TYPE_FLOAT: result = (int)val.val.fVal/2; break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It might be safer to use a union, such as VARIANT.Your structure does not have to be that complicated

typedef struct
{
   int type;
   union {
     char cVal;
     int iVal;
     float fVal;
   } val;
     
}AnyVal;

int main()
{
    AnyVal val;
    val.type = TYPE_FLOAT
    val.val.fVal = 0.0F;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why is that program using malloc() to allocate just 3 bytes??? It seems such a waste of CPU cycles. Just declare it like this: char result[3]; then remove the malloc() and free()

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

Why isn't this thread deleted????

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

If you want portability among operating sytems then use boost classes.

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

Ok here it is

int main()
{
   while(true)
   {
      read_previous_posts();
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Variable x is not being changed inside that loop, so it will print the same value of x to the file 20 times.

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

Line 3: that is not the way to pass an array. Omit the []. All you do is pass the name of the array, like this: mergesortinplace(0, (length/2), array);

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

Are you telling us that you are an illegal immegrant to one of those countries? If you are -- then Shame on you.

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

Here is an example, I think its in vb but you should be able to translate it easily to C.

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

1. Read a line from the text file
2. Break the line apart using strtok() or some other method to put each field into its own variable.
3. Write the SQL INSERT or UPDATE statement
4. Execute the statement in #3 above
5. Make whatever checks you want on the data
6. Write out the new data to another text file.

MySQL has a C library/interface API that you will have to use, or you could use ODBC. Google around and you will find both.

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

It sometimes includes threads that I have recently answered. For example, click Unanswered Threads, post in one of them, then click Unanswered Threads again -- the thread you posted in still shows up, but this time it shows correctly that there was 1 reply. I would have expected it to not have show up any more since it has been answered.

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

You don't link the dll -- only the *.lib. One way to do it is by using pragma #pragma comment(lib,"mydll.lib") Replace mydll.lib with whatever you named it.

You will have to put the dll in either the program's current working directory or one of the folders specified in the PATH environment variable.

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

include windows.h

win32 api function CreateThread()

More about that here

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

assuming you are using c++ (afterall, this is the c++ forum) Put this in your program and run it to see what it does.

#include <string>
#include <iostream>
int main()
{
   std::string line = "abcdeft>hijklmn";
   // locate the > character
   size_t pos = line.find('>');
   // if found ...
   if( pos != std::string::npos)
       line = line.substr(0,pos);
   st::cout << line << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What does the program not do that you want it to do? What are the errors? We are not here to debug and fix errors in your program, but to help you do it yourself. But before we can do that you have to know what te problems are.

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

Yes of course its possible. All you have to do is rewrite the entire file

open input file for read
open temp output file for writing
for read line read from input file
   remove what you want from the line
   write the rest to the output file

close both files
delete input file
rename output file to the name of the input file
end of program
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well, here you go. Have fun :)

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

Huh???

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

Do you want managed or unmanaged code. Its pretty easy with unmanaged code -- just google for ODBC. I'm not sure how you can do it with c++/CLR or C# programs.

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

I suggested that too but then I was accused of over thinking the problem.

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

win32 api function SetFileAttributes()

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

Agree. He'll die either from hunger or old age.

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

Making the file "read only" will NOT prevent an external application or the user from changing or deleting it. It mearly makes it more inconvenient. External applications or the user can always change the file permissions to read/write and either change the file's contents or delte it.

If you want to make it read-only only while your program has it open, that's a different story.

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

Console programs are NOT event-driven programs.

The only way to get out of Sleep() is to create another thread that sends a signal to the os to kiill that Sleep() function. But then that is a lot more complicated than the little loop I posted :)

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

Welcome to DaniWeb.

Make sure you are familiar with the Rules because you will get into trouble here if you don't write in full English words, such as "you" instead of u.

>>Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

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

One way is not to Sleep() for so long

while(true) {
   Sleep(300); // sleep 30 seconds
   if( time to waik up)
      break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't use gets() Read that link -- it contains a lot of good-to-know dos-and-don'ts.

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

Also maybe your comnputer has too little RAM. It needs at least 2 gig.

Check the amount of free hard drive space available. The OS will get very slow if the hard drive is nearly full.