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

it took the space " " that exists in the last row

Huh? The function does nothing if there is no '\n' in the string. If you want a space there then modify the function to append a space if there is no '\n'.

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

Does the input text file have a cr after the last line? If not, put one there and retest. If not then the proglem has to be choppy() -- the last line may not have '\n' at the end of the line.

void choppy( char *s )
{
   char *ptr = strrchr(s,'\n');
   if( ptr != NULL)
       *ptr = ' ';
}

[edit]I removed the last CR from my file and got lots of junk in r.txt file, for the reason I mentioned previously. The new version of choppy() fixed the problem.

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

Now run this:

        while(fgets(string, sizeof(string), p) != NULL )
            {
printf("%s", string);
              choppy(string);
printf("%s\n", string);
              cop(string, a2);
printf("%s\n", string);
              strcat(a2, nameyes);
              cop(string, a3);
printf("%s\n\n", string);
              strcat(a3, nameno);
              func(string, namesearch, nameend, a2, a3);
            }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm stumped -- I don't get that . with your program.

Put some print statements in your program so that you can see the contents of variables. Maybe that will narrow down the location of the problem. something like this:

void func(char string[1000], char namesearch[50], char nameend[50], char a2[1000], char a3[1000])
{

            FILE* pr = fopen("r.txt", "a");
            printf("a2 = \"%s\", a3 = \"%s\"\n", a2, a3);
            if(strstr (string, namesearch) || (strstr (string, nameend)))
            {
                fprintf(pr, "%s \n", a2);
            }
            else
            {
                fprintf(pr, "%s \n", a3);
            }

            fclose(pr);



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

On 32-bit systems today, you can specify a 64-bit integer as a 'long long int'

Not necessarily. Microsoft Visual C++ long long is the same size as a long which is the same size an an int. It does not recognize long long as a 64-bit int. Instead it used __int64.

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

Neither of the two compilers I used have that character there. Please repost the entire program you used.

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

What extraneous characters are in that file -- I don't see any problem with it.

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

post the file you are talking about -- attach it to you post so that the daniweb interpretor won't change it. Here is r.txt that it created for me.

Also, what is the answer to the last question, I answered with a space.

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

I just finished installing Code::Blocks with MinGW compiler, and it did not have that problem either.

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

Do you use Notepad to view the file? Dev-C++ is a pretty old and obsolete IDE/compiler. you might want to install Code::Blocks with MinGW compiler from here, it's free and current.

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

That's not a question, just a statement of what you want to do. No one but you knows why you posted that code. If you want help then you have to tell us what you want help with.

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

what compiler and operating system are you using?

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

The problem is on line 20: I replaced the space with '\0'. Put it back to a space.

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

strstr() doesn't look for words -- it just determins if the charactes in one strng are in another string. It doesn't care if there are other characters surrounding the string it is looking for. If you want just the word "bread" then you should add a space both before and after it, such as " bread " But that might present other problems, for example if the breat is at the end of the line and there is no space after it, or bread is immediately followed by a period (end of sentence).

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

the program will not differentiate words. example: Bread! = breadblabla.

The changes I made have nothing to do with that. The problem is use of strstr() on line 28.

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

the values for INT_MIN and INT_MAX are shown in the appendices as being the same as SHRT_MIN and SHRT_MAX

It is compiler dependent. That was true 30 years ago when 16-bit MS-DOS compilers such as Turbo C were the standard at the time, but modern compilers are normally 32-bit or 64-bit and the ranges of variables are not the same. The C and C++ standards do not specify the ranges, only that char is 1 byte. The size of all others depend on the compiler, and how they implement the variables is usually dependent on the platform. That is all why you have to check limits.h to find the range for your compiler.

line 14: Why are you using EOF? That is the error code when End-Of-File is reached. It applies to file i/o and should not be used for any other reason. My compiler (Visual Studio 2012) defines EOF as -1. Yours apparently defines it differently.

it would stop within its range. Why is this not occuring?

It's called Integer Overflow -- and when that happens the behavior is undefined. On the compilers I used when the max value is reached the next increment will wrap back around to 0, but there is no guarentee that all compilers do that.

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

post the file you are using.

This didn't give me any unusual characters at the end of the file. The changes I made are marked // <<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <string>



void cop(char*s1, char *s2) 
{
    strcpy(s2,s1);   // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//     int i;
//     for(i=0; s1[i]!='\0'; i++)
//         s2[i]=s1[i];
//     s2[i]='\0';   
}

void choppy( char *s )
{
    s[strcspn ( s, "\n" )] = '\0'; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<
}


void func(char string[1000], char namesearch[50], char nameend[50], char a2[1000], char a3[1000])  
{ 

            FILE* pr = fopen("r.txt", "a++");
            if(strstr (string, namesearch) || strstr (string, nameend)) 
            {
                fprintf(pr, "%s \n", a2); 
            }   
            else
            {
                fprintf(pr, "%s \n", a3); 
            }    
            fclose(pr); 



}


int main()   
{   
    char name[30];     
    printf("File: ");  
    gets(name);
    FILE* p = fopen(name, "r");  
    if(p)   
    {
        char separator[2]; 
        char ol[3] = "\n";    
        char string[1000]; 
        char nameforout[50];
        char nameend[50];
        char namesearch[50];   
        printf("Name for search: ");  
        gets(namesearch);  
        printf("separator: ");
        gets(separator);
        cop(namesearch, nameend);
        cop(namesearch, nameforout);
        strcat(namesearch, separator);
        strcat(nameend, ol);
            char nameyes[50];
            cop(nameforout, nameyes);
            strcat(nameyes,"_yes"); 
            char nameno[50];
            cop(nameforout, nameno);
            strcat(nameno,"_no");
            char a2[2000];  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<
            char a3[2000];  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<


        while(fgets(string, sizeof(string), p) != NULL )
            {              
              choppy(string);
              cop(string, a2); 
              strcat(a2, nameyes); 
              cop(string, a3); 
              strcat(a3, nameno);
              func(string, namesearch, nameend, a2, a3);
            }

        fclose(p); 
    }
    else 
         printf("\nNot open %s", name);
    printf("\nOk!!!");     
    getchar();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Curious: why didn't you use standard C string function strcpy() instead of your chop()?

lines 70 and 71: increase the size of those two because they probably aren't big enough.

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

Hard to tell without seeing the code you wrote. A couple possibilities: 1. the string was not null terminated, 2. buffer overrun (writing beyond the bounds of the buffer)

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

Scroll near the bottom of this wiki article and you will find some references.

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

What should happen with Syira?

Nuke them out of existence -- in fact, just nuke that entire continent out of existance. But first I need to dig me a deep cave and fill it full of water/food so that I won't be affected by the fallout radiation that will envelope the Earth. Ever see the movie "Planet of the Apes"? It might come true.

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

Did you bother to read the post I gave you? That is the title of the article I linked to. No one is referring to islam as a myth. A myth is something everyone believes but isn't true. Interesting read -- you might learn something.

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

Yea -- like this quote from The Myths of Islam

the Quran not only calls Muslims to submit to Allah, it also commands them to subdue people of other religions until they are in a full state of submission to Islamic rule.

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

inline functions can't be declared in a *.cpp file and expect it to be inlined in other *.cpp files. Put the entire code in the file.h header file so that the compiler can duplicate the code each time the function is called. This is consistent with the use of _inline for c++ class methods, where you write the entire function in the header file.

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

don't worry, there will be no Christians and Jews left in Syria after the Islamists win

Islam, the religion of peace.

<M/> commented: Yep, that right :D +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Change line 18 to this:

            const int NumQuestions = 10;
            string[] Question = new string[NumQuestions] 

Now the program will know how many rows are in the array, so

if (i == NumQuestions)
            {
                //Change name of start quiz button and create new event handler for button
                Next.Text = "Finish"; //changes name of Previous button to Finish
                Next.Click -= this.StartQuiz_Click; //unsubcribed orginal event handler of "Next"
                Next.Click += this.Finish_Click; //create new event handler renamed button "Finish" 
            }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

peek() reads a single character from the text file -- it can't be used to read integers except that it read a single digit.

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

The problem is fscanf() isn't removing the newline character because you never told it to do that. Make this change to your program.

fscanf(inp,"%c\n", &file_letter);

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

on line 178 test the value of i with the number of rows in the array. If i == number of rows then execute lines 183 and 184.

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

You don't need to change the event handler associated with the button click, just change the text of the button. In the event handler compare the button's text with "Next" and do whatever Next is supposed to do. When near the end of the array change the text to "Finish". If the button's text is "Finish" do whatever Finish is supposed to do. It's just a simple if statement inside the button's click event handler.

if button.text == "Next"
then
    // do whatever Next is supposed to do
    if counter == array-size then
       change button.text to "Finish"
else
// Button.txt == "Finish"
   // do whatever Finish is supposed to do
end if
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

main() is not calling MyFunc(). You need to add a call to that function between lines 8 and 10.

MyFunc() doesn't use the paramter x in the loop on line 20. Sould be: count <= x

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

My problem happens when NTP changes the clock and all my counters are not valid

The best solution is to get the time from the internet, such as from here

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

I would agree, but there is an external source that changes the computer's clock. Using UTC will not solve the problem. I think the only reliable solution is to use the clock on some other computer, such as one on a LAN or over the internet.

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

more i hate C++:(

It's a learning curve that's getting you. Stick in there and you'll get it all figured out, it just takes some time and practice.

but the static functions don't accept the normal variables

Yes, that's by design. How can a static function know the value of an instance variable? If there are 10 instances which one should it use?

and don't use properties

What do you think class objects are? In the example you posted strnome is a property of Pessoa2 class.

and events(only Visual Studio, but isn't portable:()

events are not part of the c++ language but rather an extension of the c++ language much like any other library. You get similar events with other compilers such as Borland, QT, and libraries such as wxWidgets. Don't confuse the language which is defined by c++ ISO standards committee with what is in libraries which anyone can write.

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

Actually, I was using that in about 1958, or more than 50 years ago :) It was the first typewriter I ever used.

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

If this is a web-based program than don't use c or c++. Use a scripting language designed for web servers, such as php, javascript, etc. And yes, install wamp on your development computer.

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

data cannot be initialized when declared. Besides, the default for std::string is "" (empty string), so no need to initialize it yourself anyway.

class Pessoa2 //static class
{
    string strnome;
public:
.............
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why did you declare nome inside the if statement?

I think you have the variables mixed up. strnome is a member of Pessoa2 class. You need to pay closer attention to what is and is not class members.

static void setNome(string nome)
    {

        strnome = nome;
        if(strnome.length() == 0) 
           strnome="ana";
        showname();

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

(i tryied: "if(nome==NULL)" but i get errors:()

Assuming nome is std::string, you get an error because std::string cannot be compared to NULL. Here are a few ways to check for empty string

if(nome.length() == 0)

or
if(nome.size() == 0)

or
if(nome == "")

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

what are the errors? line 4 doesn't make the whole class static, just the object declared there.

The static keyword means that there will be only one instance of the object no matter how many instances there are of the class. When you declare an object static then you also have to declare it globally in a *.cpp file. Assuming the class you posted in in a file "class.h"

// main.cpp

#include "class.h"

string  Pessoa2::strnome;

Also, make sure to include <string> header file.

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

Do you really expect me to remember a password from 30 years ago :)

<M/> commented: LOL +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I love this free tutorial -- it has an entire chapter devoted to databases.

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

use clock() instead of time(). clock() returns the number of (usually) milliseconds that have elapsed since the program started. I don't know how changing the computer's time will affect clock()

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

Before your program starts doing calculations synchronize the clock with NTP.

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

100(1+0.00417)=100.4417

That is incorrect. 100 * 1.00417 = 100.417, not 100.4417.

In any event, just a simple loop will calculate the value after N number of months.

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

The drivers are 32bit. You should consider implementing MSSQL, or Mysql or whatever db that has 64bit drivers.

I question that. On my 64-bit Windows 7 and 8 I use 32-bit database drivers.

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

Reverend: You would start a revolt with that song -- it's Country song and a lot of people hate country. I could only listen to the first 10 seconds.

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

It was down just a few minutes ago. PFO is also down.

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

What is User Acceptance Test? What is the test for? That would give us some ideas what to call those rankings.

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

somewhat

ifstream in("filename.ext");
std::string line;

while( getline(in,line) )
{
   switch(line[0])
   {

   }
}