jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it just doesn't go with the loop anymore

Sure it does. You want to keep a running total, so you want to add into your sum during each cycle. Trace it out by hand to convince yourself (which is a good thing to do with any programming problem).

  1. sum = 0, you enter 10, sum now = old value of sum + x = 0 + 10 = 10
  2. next cycle sum = 10, you enter 25, sum now = 10+25 = 35
    So it's the loop that keeps adding that new x value on.

Also, please use the code tags to surround any code that you post:

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your for loop is problematic. When i =0 it gets stuck since temp[0] !='h' is true.
Try

int count = 0;
while(temp[count] != 'h' && count<temp.size())
                count++;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

put that section of the code into a do/while loop

do{
      cout<<"Please enter a percent(<.5): "; //you're meaning for 50% right?
      cin >> percent;
      if(percent > 0.5)
               cout << "Invalid.  Re-enter\n";  
       //you could have a break statement within this if 
       //statement but I think it's tidier as is
}while(percent >.5);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
while(x!=-999);  //this semicolon ends your while right there
x++;                  //without the semicolon only this would be part of the 
                        //while loop
cout <<" enter a number (-999 to quit)";
cin >> x;

Solution:

while(x!=-999)
{
      x++;
     cout <<" enter a number (-999 to quit)";
     cin >> x;
}

EDIT: AD beat me to it lol

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you were reading strings into your numeric variables before then it should improve things a bit. One way to find out...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right so it's exactly like what I said. Create some strings to throw away (or just use 1 if you really don't need the labels at all).

string applelabel,tealabel,coffeelabel;
//or just string label;
inputFile >> applelabel;   //or inputFile >> label;
inputFile >> appleP;
inputFile >>tealabel;      //or inputFile >> label;
inputFile >> teaP;
inputFile >> coffeelabel;   //or inputFile >> label;
inputFile >> coffeeP;

That way everything's happening in the proper order.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Awesome. I hope the change will take. Well, I didn't do too much for you but I'm glad it all worked out.
Definitely post back with further questions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Indeed it seem to run fine. Runs with the 333 elements too. It's gotta be something else (obviously). Well, at least we learned your input file is not coming in the way it should...
Do you have any strange compiler settings on? Running an old compiler? In the off chance try taking stdio.h out of your includes as you already have cstdio in there.

Failing all else, you could retool that section using fstream methods.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I will tell you one thing that I did suspect before (I don't know if it has any bearing on the situation but you are writing your numeric values into your filename variable):

filename:4_Ticks_LED_Board_0000.bmp refcount:8
filename:272 refcount:201
filename:10 refcount:11
filename:291 refcount:201
filename:10 refcount:12
filename:308 refcount:202
filename:10 refcount:11
filename:280 refcount:217
filename:11 refcount:10
filename:301 refcount:217
filename:10 refcount:11
filename:273 refcount:233
filename:9 refcount:11
filename:289 refcount:233
filename:11 refcount:10
filename:308 refcount:233
filename:10 refcount:12

Maybe that's what you wanted.

Well this

FILE* info;
	char* infoname;
    char* fullname[PATH_MAX];
    char detfilename[PATH_MAX];
    char* filename;
    char detname[] = "det-";


	filename = "kot1.txt";
	//saveDetected = 0;
	infoname = "kot1.txt";

	info = fopen(infoname, "r");

	 if( info != NULL )
	 {

        
        int refcount;

		filename = new char;

		while( !feof( info ) )
		{
			if( fscanf( info, "%s %d", filename, &refcount ) != 2 || refcount <= 0 ){ break;}
			printf("filename:%s refcount:%d\n",filename,refcount);

			int * kot = new int;



		}/*while( !feof( info ) )*/

	}/* if( info != NULL )*/

	fclose(info);

	return 0;

ran without a hitch so I don't know what to tell you. The allocation seems to take place too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I do believe you. I'm just confused as to what it could be. Could you put up a representation of a data file so I can run that snippet on my machine?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How long are the filenames? I'm afraid that I'm not as versed in the stdio.h functions as I used to be, but I still have a strong suspicion that either you're running over the filename array (or not allocating any room for it in the first place having no filename = new char[something]) or you're not leaving enough room for the null terminus.
I was going through the forums to see if I could find a good concrete example that was similar to yours but I didn't turn up much of anything.
So, I apologize as the only thing I'm confident of is that somewhere in that call you are corrupting memory.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The one outside of the while above is still "live" @ line 98. What does info contain after you go through the loop once? Since if you "new" it filename's not going to point to anything since you have clobbered what was written in it up above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
filename = new char;
fscanf( info, "%s %d", filename, &refcount )

I'm not sure that this is working the way you want it to. You redeclare a pointer and then you try to write that to a string. It's confusing things and you might be goofing up the placement of something else.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit above too :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

when I call blob_detect() which uses included .cpp
function which calls .cpp files

I'm a tad confused about what you mean by that. Are you saying that you've included the source for the method in another file in your project?

Also while there is still editing time on your old post, put some code tags around your work
It makes it easier to read and preserves the spacing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're doing C++ you should use fstream, it makes things a lot more intuitive, I think.
If you had no space between level and = you could have something like

ifstream infile("Doc.txt");
while(infile >> tempstring)
{
         //add tempstring to vector or array
         infile >> tempvalue;
         //add tempvalue to it's own array or vector
} //this way you can read in as many lines as you need to
//you'd have to specify the array size before hand or ask the user for 
//how many records

So, if you want to stick with the C style of doing it that's still ok, just wanted to offer the option to you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does the layout of the file look like, for instance are:

inputFile >> appleP;
inputFile >> teaP;
inputFile >> coffeeP;

appleP, teaP and coffeeP all separated by space or a newline? I suspect if they are laid out like the 2 line sample you gave you are trying to read the "goods" into your price variables.

As far as the setprecision goes, I don't see anything explicitly wrong in your code, so I'm not sure.

Put a cin.get() in between lines 53 and 54 so that you get a "pause" effect so you can check out what's on screen. If necessary you can output what you've just input to check it to make sure (I know you think the problem lies in the output but it couldn't hurt).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How far can you get in the process? Can you open up a file? Do you want to read it straight out of the file into one big string to put it in the message box? Try to see how much headway you can make first and then post whatever code you've got. I assume since you want a messagebox that you are familiar with MFC?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had wondered about that actually. I was writing it in because I thought it was a good habit. I guess that settles it. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, see this post and for an article with lots of examples, see this.

(sorry adatapost, I was already in process when you posted)

kvprajapati commented: You are always helpful +6
chaienbungbu commented: Thanks. After reading your example, I remember that my problem related to "passing by ref". +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

constructArray_2 (a, MAX); You are passing in the value a to your function but there is no a defined in main(). Where is this value supposed to come from?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
private void button1_Click(object sender, EventArgs e)
        {

            //http://dotnetperls.com/filename-datetime
            
            string fName = string.Format("myfile-{0:yyyy-MM-dd_hh-mm-ss-tt}.txt",
            DateTime.Now);

            using (StreamWriter sw = new StreamWriter(fName))
            {
               sw.WriteLine(textBox1.Text);
               sw.Close();

            }
        }

I found the way to get the formatting into one that is acceptable to file names on that site in the comments. Otherwise you can probably play around with the ordering of the time-date information.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please don't bump your threads so soon, have a bit of patience. I was actually just about to give you: e = d.Base::operator*(1.0); I'm fairly sure that in cases like this you lose the more aesthetic syntax, but I believe that this works.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check to see if it's still running somewhere (if it's not in the taskbar, open the task manager and see if it's still there, end the process if it is). Failing that try rebooting. If that still doesn't help you might have to create a new project and incorporate the existing source files.

EDIT: LOL AD had me by 2 seconds or less hehe

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hate to be a "Me too" but me too just now. I had also experienced the 15 second message Salem got a few days ago. I'm going to lie awake tonight staring at the ceiling wondering why me. :D

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
void getFname(string path,string str[], int & position)
{
	string t=(path+"*.txt");
	cout <<"Path "<<t<<endl;
	if((hfile=_findfirst(t.c_str(),&c_file))==-1L)
	{}
			
	else
	{
                position=0;
		//str[0]=path+c_file.name;
		//position++;    [SEE BELOW]
			
				
		do{				
					
			str[position]=path+c_file.name;
			position++;
					
					
			}while(_findnext(hfile,&c_file)==0);

I made a mistake, you need to take out those lines too as it's accomplished in the first pass of the do/while. Otherwise you're doubling your first file.

There's something wrong with the program that it doesn't find the tokens in anything after the first file. Have you run across this?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do you display your other characters? I would just output the actual 'Q' on the die and add the extra character as if you were adding the next actual letter.

e.g.,

cout <<dice[i][j];
if(dice[i][j] == 'Q')
     cout<<'u';
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm going to be shipping out so wrestle with that a bit more on your own. In my further testing there is some issue with the path as it is coming in from main() (it seems to have extra spaces or an extra \n in there somewhere).

It's coming along. I think you'll be proud of the end result. Happy debugging.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm going to be shipping out so wrestle with that a bit more on your own. In my further testing there is some issue with the path as it is coming in from main() (it seems to have extra spaces or an extra \n in there somewhere).

It's coming along. I think you'll be proud of the end result. Happy debugging.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
bool manipulation1(string path)	
		{	
			fstream  my_file;
			string line;
			char * cstr;
			char	* p;
			char delim[]=" :'.,?><_+{}[]();";
                	string ext=".txt";
			bool found=false;
			string strArray[20]; //keep this to use it 
			
	                      // string* d= get rid of this	
             f.getFname(path,strArray);

                            //now skip all the strArray[i] = D[i] stuff but this time
                           //you'll have the correct filenames

And more importantly you know that everything up until that point is working. Now you can make the similar changes in manipulation2. Then we can make sure that everything's working after that point in that method. Debugging, it's a wonderful thing.

EDIT: Now that I'm looking at it, it might be advantageous to either return or send in as a reference parameter the "position" variable, so you can use that to control your loops.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was telling you to send in the array (by pointer, I said by reference by mistake) rather than returning a pointer like you did. So declare your array of strings (to store the filenames) in your fileManipulation class rather than in the file class, e.g.,

string fnames[20]; //I'd do more than that if you have big directories
getFname(path,fnames);

-then-
you can access as fnames[0], etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Got part of it:
In your file class

void getFname(string path,string str[]) 
         {           //change to returning an array
		 //by reference, just to make things easier

                     //leave the rest the same
                      //but instead of your while
                   do{				
			str[position]=path+c_file.name;
			position++;
			}while(_findnext(hfile,&c_file)==0);
           //and get rid of the return statement

Your while loop was only executing once after the initial time, I think it needs the prior result as a seed for the next (I'm sure there's more to it than that but I am not really familiar enough with it to say).

So test that on a few directories and try to reintegrate it with your other code.

yahh , it works.

I don't believe that for a second after I spent all that time looking over it for you! (to be polite) It was getting the first and last items of the directory and nothing more.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The program only asks the user to input the word which he wants to search in specific directory and folder ,then my program searches all the files in that folder, and check whether the word is found or not.
So its the responsibility of my prog to search for the file names.

Have you tested your File class in isolation, that is does it (by itself) produce a list of files from a given directory?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

whatever input , i give, it says word not found, file not opened!!

See my edit above if it hadn't come through.

My honest opinion, I would cut and paste all that elaborate menu stuff out for the time being.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What's the problem you have been having with it?

In your main() you never explicitly ask for the filename, you just tack the extension onto the folder name.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you have to mention its return type "void" or "int".

void main is actually incorrect (though your compiler may take it)
See this article.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need to put the return type of the function before its name when you are calling it (definitely need it in the prototype and in the definition though) reverse(s,i); is all you need on that line you have marked.

Also, you should put int in front of main (your compiler might be doing it implicitly but don't rely on that)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My password is always the day of the week my password was created. I tell people that, too, because it's not like they'll know what day of the week I created it. That makes it secure. Extremely secure.

And assuming you don't vary case, there's like 10 to the.... er 2 to the... oh wait there's only seven things to guess. They'll never catch on. :) (it's more fun if you weren't kidding)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That is correct, if you use rand() % 6 + 1 you will be good. Also, when you define a function:

Yes, to get numbers from 1 to 6 that is what you would do, but he's stored them in array (zero based) so you don't need the +1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

rand() % 7 is going to get you numbers between 0 and 6 which will overstep the bounds of your array by 1 if a 6 is pulled.

I'm confused why you broke up the loop like you did?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If find() doesn't find what I want, then found == string::npos else it outputs an integral value.what does that integral value meanns??

http://www.cplusplus.com/reference/string/string/find/
It's the index of the first occurrence of the string stored in word within your line of text that you have read in. So a multiple line file will yield a value for found for each line. However, find is able to locate your search word within another word of the text, e.g., if you are looking for "the" and the word "anthem" is in your text.

if the specified word is found then i want to display the attributes of that text file , like its name , size , directory etc.

Well filename is quite easy as you already have it from the user. The other information you'll have to get in an OS dependent way. I am assuming you are using windows but there are functions in *nix to accomplish the same thing. Search around the forums for some pointers, but you can look up the documentation for io.h or take a look at this for the specific Win32 functions for file handling (you'll have to include windows.h and make sure to designate your project as a Win32 Console app to make sure you have all the appropriate libraries).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just a couple of changes:

my_file.open ((getname()+ext).c_str());  // need a c-string for this
		//you can delete { that was on this line and its match	
	            if (my_file.is_open())  //this is ok, included just for context			
		   {				
			while (getline (my_file,line))
			{  //see post #7 where Lerner explained

With those changes it worked just fine for me. Output a space after found in your highlighted code to see the indexes.

As far as the file attributes go, which do you need? You have included io.h which you can use but the caveat is that most of those functions are non-portable. You can find a reference for it with your compiler docs or there seem to be a few out there on the web (make sure it matches your implementation).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'd put it in a 2D array. That way you can iterate over the rows and pick a random die face from each to face "up". Making your swaps with 16 different arrays could turn into a nightmare. I don't have too much to add besides that. Sounds like a neat (and doable) project!

Definitely post back if you have any further questions about it and hopefully you'll get some other suggestions on this thread.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look under:
Project Menu/Properties/Configuration Properties/General/Output Directory

I think this is to what you are referring.

Also see Project Menu/Properties/Configuration Properties/Debugging/Working Directory

I'm not sure what the exact distinction between those two is, but the latter might let you just specify the directory for the dlls without having to spawn the exe there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You'll have to have an embedded character especially for eyerolls (à la Narue). It would be like the letter e of sarcasm.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sold separately? Goes with: Batteries not included. Some assembly required. You need at least 2/3 of those to qualify for a 1980's toy commercial.

So rather than your recipient think you're being sarcastic, they instead think you're an idiot who can't use a keyboard.

"nt nlik ne1 els w no"

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Would something like this work (if you used Visible = false in your resize method instead of Hide())?

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
        if(this.WindowState == FormWindowState.Minimized)
               this.WindowState = FormWindowState.Normal;
       this.Visible = true;          
}
j4jawaid commented: Thanks. +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So do your bubble sort and allow the other array to follow along (when you're update index numbers for A array in your sort, update B with the same changes.

Then comb along A (with a loop) and find the first set of duplicates (check index n versus index n+1, and n versus n+2 if there's a match).

Over those index numbers do a mini bubble sort of the B array (since the A values are all the same leave them in place and just sort the select B values). Move on to your next set of duplicates, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think since the other array must track the indicies of the first it would be difficult to use the STL methods anyway. What are some of the things you have tried?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Using 2 datetime pickers you can get the timespan between them

TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value;
            MessageBox.Show(ts.ToString());

To do what you're suggesting would probably take the user putting in one of them to the DTP, hitting a button to lock the value into one DateTime object, choosing a new date then hitting the button again (or something to that effect).
Either way the timespan is the way to measure the difference and then you can take the timespan apart based on seconds, minutes, total seconds, etc.