masa 0 Light Poster

Hi everyone
How can I embeded an image to OLE Object field using Long Binary data.
and what Long Binary data means and how to use it.

does anyone have any ideas on

I would to display images in my asp page. I am trying to insert the images in to MS Access using long binary data.
so How can I insert a long binary data to ole object field.

thanks in advance

masa 0 Light Poster

Look in MSDN for GetOpenFileName and SetSaveFileName functions.

Hi have this

LPTSTR CommonD_OpenFile()


    {
    
		char* lpszFileName;
    		OPENFILENAME ofn; // common dialog box structure
    	char szFile[260]; // buffer for file name
    	HWND hwnd; // owner window
		hwnd = 0;
		// Initialize OPENFILENAME
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFile = szFile;
    	//
    	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
    	// use the contents of szFile to initialize itself.
    	//
    	ofn.lpstrFile[0] = '\0';
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "Bitmap Files\0*.csv\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
		// Display the Open dialog box. 
		if (GetOpenFileName(&ofn)==TRUE) //Or use GetSaveFileName, same work


        	{
        		int i = (int)strlen(ofn.lpstrFile);
        		lpszFileName = new char[i+10];//init buffer to size needed
        		strcpy(lpszFileName,ofn.lpstrFile); //copy over the file name
        		return(lpszFileName); 
        	}
        	else


            	{
            		lpszFileName = new TCHAR[2];
            		lpszFileName[0]= __TEXT('\0');
            		return (lpszFileName);
		}
        }

then I call it in main
what I would like to do is. I going to post my program to the user. so I would like to enable the user to enter the path for the input file and the output file for the first time and then the system suppose to remember the path and work upon it.

masa 0 Light Poster

Hi evryone
I using MVC++ and built my project using Win32 app.
My program do not have any interfaces. it reads files and it put the output in another file. ( I do not mind put interface only to enter the path)

the thing is I made my program read the input file from specific directory and put the output in the specify directory. the probelm now is that I would like the user to inter the dirctory of the input file and the output file is this possible if yes, please tell me how to do it, I do not have any idea.

"C:\\Wadi\\In\\Log_01.csv" my in file directory
"C:\\Wadi\\Out\\Daily_Summary_%d.csv" my out file directory

now I would like to enable the user to enter his path for the input file and the output file.

masa 0 Light Poster

Hi everyone
I used MVC++ and built a project win32 app( world) which has in it folder(world.dsw, world.dsp, world.cpp,world..., Input.csv,output.csv) , my program do not have an interface.
because it open and read in.csv and do some calculate to put the output in out.csv.

Now I would like to make the file world.exe . so after that I can scheduler a task in widow xp to run the world.exe in a specific time.

How can I make my world.exe


thank you

masa 0 Light Poster

thank you I made a new function and now I am getting the right result.
thak you for you support.

masa 0 Light Poster

Hi
I really sorry for all this mess, but could you please check what my mistake ( I really confuse). I am going to post the whole code and the result.

float sumcol(int col,string line)
{
	int pos;
   float sums[3] = {0.0};
	// find the (col-1)th comma in the string
	pos = 0;
	for(int k = 0;k < line.size() && pos < (col-1); k++)
		if(line[k] == ',')
			pos++;
	// remove the first (col-1) columns from the string
	line = line.substr(pos+1);
	
	return atof(line.c_str());
}

int main()
{

	ifstream input_file("Log_05.csv");
    string line;
    int count;
    float sums[33] = {0.0}, avg[]= {0.0};
	float max = 0.0;
	int arraysize;
	int array[] = {6,15,16,17,22,23,24,28,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 };

    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
       getline(input_file, line);
	   count = 8;                  // We are in the eighth line
       while(count <= 1447) // We have to add until 1447 lines..
	   {      
			getline(input_file,line);
			// number of elements in the above array
			arraysize = sizeof(array) / sizeof(array[0]);
			for(int col = 0; col < arraysize; col++)
			{
				sums[col] += sumcol(array[col],line);
			}
			 count++;        // Increment the count, to go to the next line

		}
	   count-=8 ;
	   cout << count;
		for(i = 0; i < arraysize; i++)
		{
			cout<<endl<<"The sum of all values of column " << array[i] << " is : "<<sums[i]<<endl;
			avg[i] = sums[i] / count ;
			cout<<endl<<"The avg of all values of column " << array[i] << …
masa 0 Light Poster

Hi
I worked on it with another file called book.csv, all the calculation was right.
the problem is with the original file this require to be read Log_05.csv as it contain dat,time different format.

float sumcol(int col,string line)
{
	int pos;
   float sums[5] = {0.0};
	// find the (col-1)th comma in the string
	pos = 0;
	for(int k = 0;k < line.size() && pos < (col-1); k++)
		if(line[k] == ',')
			pos++;
	// remove the first (col-1) columns from the string
	line = line.substr(pos+1);
	
	return atof(line.c_str());
}

int main()
{

	ifstream input_file("Book1.csv");
    string line;
    int count;
    float sums[5] = {0.0}, avg[]= {0.0};
	float max = 0.0;
	int arraysize;
	int array[] = {2,4,6,8,10};//6,15,16,17,22,23,24,28,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 };

    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
       getline(input_file, line, '\n');
	   count = 8;                  // We are in the eighth line
       while(count <= 15) // We have to add until 1447 lines..
	   {      
			getline(input_file,line);
			// number of elements in the above array
			arraysize = sizeof(array) / sizeof(array[0]);
			for(int col = 0; col < arraysize; col++)
			{
				sums[col] += sumcol(array[col],line);
			}
			 count++;        // Increment the count, to go to the next line

		}
	   count-=8 ;
	   cout << count;
		for(i = 0; i < arraysize; i++)
		{
			cout<<endl<<"The sum of all values of column " << array[i] << " is : "<<sums[i]<<endl;
			avg[i] = sums[i] / count ;
			cout<<endl<<"The avg of all values of …
masa 0 Light Poster

Hi
I change the cout and got the column number, but still all the calculation is giving wrong result.

float sumcol(int col,string line)
{
	int pos;
   float sums[33] = {0.0};
	// find the (col-1)th comma in the string
	pos = 0;
	for(int k = 0;k < line.size() && pos < (col-1); k++)
		if(line[k] == ',')
			pos++;
	// remove the first (col-1) columns from the string
	line = line.substr(pos+1);
	
	return atof(line.c_str());
}

int main()
{

	ifstream input_file("Log_05.csv");
    string line;
    int count;
    float sums[33] = {0.0}, avg[33]={0.0};
	float max = 0.0;
	int arraysize;
	int array[] = {6,15,16,17,22,23,28,24,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 };

    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
       getline(input_file, line, '\n');
	   count = 8;                  // We are in the eighth line
       while(count <= 1447) // We have to add until 1447 lines..
	   {      
			getline(input_file,line);			
			// number of elements in the above array
			arraysize = sizeof(array) / sizeof(array[0]);
			for(int col = 0; col < arraysize; col++)
			{
				sums[col] += sumcol(array[col],line);
			}
			 count++;        // Increment the count, to go to the next line

		}
		for(i = 0; i < arraysize; i++)
		{
			cout<<endl<<"The sum of all values of column " << array[i] << " is : "<<sums[i]<<endl;
			avg[i] = sums[i] / count ;
			cout<<endl<<"The avg of all values of column " << array[i] << " is : "<<avg[i]<<endl; 
		}
			

   }
    
 return 0;
}

the result is not right. :cry:

The …
masa 0 Light Poster

Hi Ancient dragon
I did that

float sumcol(int col,string line)
{
	int pos;
   float sums[33] = {0.0}; // we need 33 column
	// find the (col-1)th comma in the string
	pos = 0;
	for(int k = 0;k < line.size() && pos < (col-1); k++)
		if(line[k] == ',')
			pos++;
	// remove the first (col-1) columns from the string
	line = line.substr(pos+1);
	
	return atof(line.c_str());
}

int main()
{

	ifstream input_file("Log_05.csv");
    string line;
    int count;
    float sums[33] = {0.0};
	float max = 0.0;
	int arraysize;
	int array[] = {5,6,15,16,17,22,23,28,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 };

    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
       getline(input_file, line, '\n');
	   count = 8;                  // We are in the eighth line
       while(count <= 1447) // We have to add until 1447 lines..
	   {      
			getline(input_file,line);			
			// number of elements in the above array
			arraysize = sizeof(array) / sizeof(array[0]);
			for(int col = 0; col < arraysize; col++)
			{
				sums[col] += sumcol(array[col],line);
			}
			 count++;        // Increment the count, to go to the next line

		}
		for(i = 0; i < arraysize; i++)
		{
			cout<<endl<<"The sum of all values of column " << i+1 << " is : "<<sums[i]<<endl;
			float avg = sums[i] / count ;
			cout<<endl<<"The avg of all values of column " << i+1 << " is : "<<avg<<endl; 
		}
			

   }
    
 return 0;
}

but it gives unordinary output

The sum of all values of column 1 is : …
masa 0 Light Poster

Hi ancient dragon

float sumcol(int col,string line)
{
	int pos;
   float sums[196] = {0.0};
	// find the (col-1)th comma in the string
	pos = 0;
	for(int k = 0;k < line.size() && pos < (col-1); k++)
		if(line[k] == ',')
			pos++;
	// remove the first (col-1) columns from the string
	line = line.substr(pos+1);
	
	return atof(line.c_str());
}

int main()
{

	ifstream input_file("Logos_05.csv");
    string line;
    int count;
    float sums[196] = {0.0};
	float value;
    float max = 0.0;
    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
           getline(input_file, line, '\n');
	   count = 8;                  // We are in the eighth line
       while(count <= 1447) 
	   {      // We have to add until 1447 lines..
			getline(input_file,line);
 			for(int col = 0; col < 196; col++)
			   sums[col] += sumcol(col,line);
			 count++;        // Increment the count, to go to the next line

		}
		   
			cout << count;
		for(i = 0; i < 196; i++)
		{
			cout<<endl<<"The sum of all values of column " << i+1 << " is : "<<sums[i]<<endl;
			float avg = sums[i] / count ;
			cout<<endl<<"The avg of all values of column " << i+1 << " is : "<<avg<<endl; 
		}
			

   }
    
 return 0;
}

I did this function that get me the sum of all the column, but the problem I do not need all the column I need sum,avg for only 5,6,15,16,17,22,23,28,29,30,37,38,39,44,45,46,50,51,52,61,71,81,91,101,111,121,131,141,151,161,171,181,191 and some of these column are int and some float. so can you …

masa 0 Light Poster

Hi
I did this function, it return only one column value ( I need the rest as well)

int pass_column(int column);
int main()
{

ifstream input_file("Log_05.csv");
    string line;
    int count,col=0;
    float sum = 0.0, value;
    float max = 0.0;
    if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
           getline(input_file, line, '\n');
		   count = 8;                  // We are in the eighth line
           while(count <= 1447) // We have to add until 1447 lines..
			{      
			   
			  for(int i = 0; i < pass_column(col); i++)
					
					 getline(input_file, line, ',');    // Get the first col columns.
					 cout<<line<<endl;       // Print the col column for verification.
					 value = atof(line.c_str());// Convert the col column into float
					 sum += value;	//add value to sum
					 getline(input_file, line, '\n');    // Go to the next line..
					 	if ( max < value)
					{
						max= value;
					}
						col++;
					 count++;        // Increment the count, to go to the next line

			}
		   
			cout << count;
			cout<<endl<<"The max of all values of column 5 is : "<<max<<endl;
			cout<<endl<<"The sum of all values of column 5 is : "<<sum<<endl;
			float avg = sum / count ;
			cout<<endl<<"The avg of all values of column 5 is : "<<avg<<endl; 
			

   }
    
 return 0;
}

int pass_column(int column)
{
  int i=0;
  while ( i<196)
  {
	switch (i)
	{
	 case 15:
		column=i;
		return (column);

		break;
	 case 193:
		column=i;
		return (column);
		break;
	 case 195:
		 column=i;
		 return (column);
		break;
	}
  i++;
  } …
masa 0 Light Poster

Hi
thanks I will do it in a function.
one think, in the previous post, it has the code

int main()
{
int main()
{
....
}
}

is a paste error, or ?

masa 0 Light Poster

Hi
I used if to get the sum of the 5 column and another if to get the sum for the 7 column, and I have another columns need to have the same operation .( that s why I tried as well using swtich statement).
I am not sure about the combine statement how it is going to look like in with many column need the to find sum and avg for them

masa 0 Light Poster

Hi Anceint dragon
you are right about it.
I tried to do like that, but it giving me wrong result

if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
           getline(input_file, line, '\n');
		   count = 8;                  // We are in the eighth line
           while(count <= 1447) 
			{      // We have to add until 1447 lines..
			   ++col;
              if (col =5)
			  { for(int i = 0; i < col; i++)
					
					 getline(input_file, line, ',');    // Get the first 5 columns.
					 cout<<line<<endl;       // Print the 5th column for verification.
					 value = atof(line.c_str());// Convert the 5th column into float
					 sum += value;	//add value to sum
					 getline(input_file, line, '\n');    // Go to the next line..*/
			  } 
					 count++;        // Increment the count, to go to the next line
					
				if ( col =7)
				{for(int i = 0; i < col; i++)
					
					 getline(input_file, line, ',');    // Get the first 7 columns.
					 cout<<line<<endl;       // Print the 7th column for verification.
					 value1 = atof(line.c_str());// Convert the 7th column into float
					 sum1 += value1;	//add value to sum
					 getline(input_file, line, '\n');    // Go to the next line..*/
			  } 
				 count++;        // Increment the count, to go to the next line
			}
			cout << count;
			cout<<endl<<"The sum of all values of column 5 is : "<<sum<<endl;
			cout<<endl<<"The sum of all values of column 7 is : "<<sum1<<endl;
			float avg = sum / count ;
			cout<<endl<<"The avg of all values …
masa 0 Light Poster

Hi
is there anyone have an idea :idea: on how could i get the column 7 from the file, I did it for column 5. or how could I continue to make it take other columns.

if ( input_file.fail ())
    { 
        cout << "Error opening file.";
    }
    else
    {
       for(int i = 0; i < 7; i++)    // Scan the first 7 lines, which is not required
           getline(input_file, line, '\n');
		   count = 8;                  // We are in the eighth line
           while(count <= 1447) 
			{      // We have to add until 1447 lines..
            
				for(int i = 0; i < 5; i++)
					getline(input_file, line, ',');    // Get the first 5 columns.
					cout<<line<<endl;       // Print the 5th column for verification.
					value = atof(line.c_str());// Convert the 5th column into float
					sum += value;	//add value to sum
					getline(input_file, line, '\n');    // Go to the next line..
					count++;        // Increment the count, to go to the next line
				}
			cout << count;
			cout<<endl<<"The sum of all values of column 5 is : "<<sum<<endl;
	
			float avg = sum / count ;
			cout<<endl<<"The avg of all values of column 5 is : "<<avg<<endl;   
   }

thank you

masa 0 Light Poster

thank you everyone for the answer

masa 0 Light Poster

Hi
I would like to know which is better. inialise a value like

int i=0;

or like this.

int i(0);

and why.

masa 0 Light Poster

Thank you

masa 0 Light Poster

Hi
if you have a file on c drive under a particular folder how can you open it

ifstream input(filename);

if your file name is available in c drive on myfile folder (filename=" C:\myfile\hi.txt") :idea:

masa 0 Light Poster

thank you all I got it. solved

masa 0 Light Poster

Hi
thank you for your reply, you are right I found what I am asking about.leave it.
one thing, if you define a file like this

char filename[20]="hi.txt";
FILE *fp;
	
	/*Open input file*/
	fp = fopen(filename,"r");
	if (fp != NULL)
	{
		 fprintf(stderr,"Could open input file.\n");
	}
	else
	{
		fprintf(stderr,"Could not open input file.\n");
		result = -1;
	}

now fp suppose to carry the filename, am I right?
so if I used

cout << "the file name is "<< fp << endl;

is suppose to print the filename hi.txt , but actually it prints on screen 00478998.
why is that.
it seems a silly question, but I my brain froozen

masa 0 Light Poster

hi
if you use

rewind( FILE *in);

what you can use for

I/O stream library
ifstream in(ff.txt);
masa 0 Light Poster

can I know how you mark something solve.

masa 0 Light Poster

Sorry for not making my self clear enough, if you see the following thread
http://www.daniweb.com/techtalkforums/thread36795-1.html
so if you check this thread you will find that they put the log.csv file in a dynamic array, before finding the min and the max ( is this necesary :?: ) or they can only open the Log.csv file and then make some function to find the min and the max.

thanks in advance

masa 0 Light Poster

Hi
when I was looking on some thread, a question :?: comes to my mind, when you have a file like the one Log.csv from Aldin post, do you need to put it in a dynamic array to get the max and the min and the date..etc.
or you can only open the file and built some function to get the max the min ..etc.

thank you

masa 0 Light Poster

That's already been answered in this thread -- just read some of the earlier posts (#13 and #14). Use sprintf() strftime to format the string.

Hi
thanks I forget about sprintf(), I did it thanks again. :cheesy:

masa 0 Light Poster

Hi
thank you salem. I have a nother question.

month= newtime ->tm_mon +1;
year=newtime ->tm_year + 1900;
ofstream out("myfile(month)_(year).txt");

the out put file, I like to carry month like 12 and year2005, but it actually gives me
the out put file like this myfile(month)_(year).txt, why it is wrong I pass in it the value of the month and the year.

masa 0 Light Poster

Hi
thanks ancient dragon for remind me with that, the problem I am facing is in this condition, which I suppose is right.

if ( filename == "day_01.txt")

it suppose to print

cout << "1";

but actually it gives

cout << "2";

so it should have something wrong but I am not sure what is it.

masa 0 Light Poster

Hi Dave
I was looking on this code.

#include <stdio.h>
#include <time.h>

char *foo(int days, const char *format, char *text, size_t size)
{
   time_t t;
   if ( time ( &t ) != (time_t)(-1) )
   {
      struct tm *local = localtime ( &t );
      if ( local )
      {
         local->tm_mday += days;
         t = mktime ( local );
         if ( t != (time_t)(-1) )
         {
            local = localtime ( &t );
            if ( local )
            {
               if ( strftime ( text, size, format, local ) )
               {
                  return text;
               }
            }
         }
      }
   }
   return 0;
}

int main(void)
{
   char filename[20];
   if ( foo(-1, "day_%d.txt", filename, sizeof filename) )
   {
      printf("filename = \"%s\"\n", filename);
   }
   return 0;
}

/* my output
filename = "day_01.txt"
*/

can we use the filename and make a condition for it., like

time( &long_time );              
newtime = localtime(&long_time );  
day = newtime->tm_mday;				
month= newtime ->tm_mon;
year=newtime ->tm_year;

	if ( filename == "day_01.txt")
			{
				ofstream out("myfile(month)_(year).csv");
				writestuff(out); 
				out.close();
				cout << "1";
			}
		else 
			{
				ofstream out("myfile(month)_(year).csv");
				writestuff(out); 
				out.close();
				cout << "2";
			}

is it possible to make a new file whenever the filename is day_01.txt or otherwise it is going to open the same file to write in it.

thanks for everyone in advance