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

Yes it is -- and you can keep all that snow where you are, I don't want it here :) But I'll bet winter sports are great where you live.

[edit]I couldn't help myself -- I just had to repost that picture on Facebook didn't mention anyone's name. I don't think anyone around here has ever seen that much snow unless they traveled up to Canida.

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

This question has been asked and answered over a million times. Why don't you just use google to get your homework done.

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

To do it in either C or C++ you need to read some tutorials about socket programming. There is a difference between MS-Windows and *nix sockets, so you first have to determine which platform you are writing for. Here are some google links that you might find helpful.

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

Please don't refer to people you don't know as "dear". No one here is your sweatheart.

Did you read this thread?

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

Relatively nice day today. Yesterday was about 15.5C but today is -10C. At least there's no snow on the ground :)

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

With VC++ 2014 I have to include windows.h before sqlext.h

#include <Windows.h>
#include <sqlext.h>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Or smaller? I know the number of bits im a byte varies quite a bit from one patform to another, but AFAIK a char is always 1 byte.

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

If you want it to output unicode strings then std::cout and std::cin won't work because they are not unicode functions. Example:

int main()
{
    wchar_t buf[255] = { 0 };
    wcout << L"Enter something/\n";
    wcin >> buf;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, it was off, the range is -128 to 127

define SCHAR_MIN   (-128)      /* minimum signed char value */
#define SCHAR_MAX     127       /* maximum signed char value */
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The quote you posted does NOT say globals are static by default, it says just the opposite. "external linkage" means that if there are two *.c files, say A.c and B.c, a global variable declared in A.c can be used in B.c. In B.c you declare the variable as extern.

Example use:

A.c

#include <stdio.h>

int MyGlobal = 123;

int main()
{

}

/////////////////////////////////////////

B.c

#include <stdio.h>

extern int MyhGlobal;

void foo()
{
   printf("%d\n", MyGlobal);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

short and long are two of the numeric data types (char, short, int, long, float and double). Only char has a guarenteed size, which is 1 byte with a range of -127 to 126. The size of all the others is compiler-dependent, so you have to look in the compiler's header file limits.h to find out what they are.

typedef just creates an alias name for something else. For example, typedef int MYINT; creates a new datatype name MYINT that's the same as int.

const just means the value of the variable or function can't be changed.

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

Because after you enter a number from the keyboard you have to press the <Return> or <Enter> key. That key, '\n' remains in the kayboard buffer until the next input is made. In the case of another number, cin skips all leading whitespace characters (space, newline, tab, and backspace) then process the remaining keys up to the first non-numeric digit. But, in the case of character array cin starts with the first character it finds in the keyboard buffer (which is now '\n') and stops when it finds end-of-data or a newline. Since the newline is the first character in the buffer cin won't do anything.

The way to solve that problem is to clear the keyboard buffer before calling cin. There is a thread here that explains how to do that in great detail.

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

I usually use the macros in tchar.h to make programs UNICODE friendly. If you search MSDN for the string function it will tell you what macro to use from tchar.h. For example, strcmp() becomes _tcscmp(), and for string literals use the _TEXT macro, such as _TEXT("Hello World");

There are no macros that easily convert character arrays to wide character arrays, use one of the convertion functions for that.

The only suggestion I have for your code is this: (Note: I never heard of unicout but I'm assuming it's part of C++11 standard which I have not studied. But from what I read using google just now c++11 support for UNICODE is pretty poor.)

#include <tchar.h>

....

int main()
{
    const _TCHAR s[] = "Русский текст в консоли\n";
    unicout<<s;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The default is non-static.

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

I can't help you if you don't post the code that exhibits the problem(s).

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

line 11 is wrong. There is no such command as c:\Computer.

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

Try this: Your function is exiting the loop after the first iteration whether the username and password are found or not.

int POSConsole::Authenticate(string _userID, string _password)
{   
    bool failedLogin=false;
    int returnValue=0;

    _password = Encrypt (_password);     //Encrypt user enter password to compare with vector  

        for (int index = 0; index < cashierVector.size(); index++)
        {
                if ( (_userID == cashierVector[index].getUserID()) && 
                 (_password == cashierVector[index].getPassword()))
                {
                        returnValue=1;                                                     
                        system("clear");
                        POSMenu();                                
                        break;                                
                }
        }
        if( returnValue == 0)
        {
             cout << "Invalid user login information. Please try again.\n";           
             failCount++;                   
        }

        return returnValue;   

// The following is unreachable code!
        if (failCount == 3)                
         {         
              cout << "You have used maximum attempts to login. Your account has been locked." << endl;
              exit (0);                       
         }

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

Stargate -- oldie but goodie.

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

Another option is to remove the L in front of the two string literals.

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

this one works as expected.

void sortstudents()
{
    clearWindow();
    FILE *fp;
    fp = fopen("record.txt", "r");
    if (fp != NULL)
    {

        //stud *arr = (stud *)malloc(chunck);
        stud starray[25] = { 0 };

        int count = 0;
        while (fread(&starray[count], sizeof(stu), 1, fp) > 0)
            count++;
        fclose(fp);

        gotoxy(37, 12); printf("The record is Found");
        gotoxy(37, 13); printf("--------------------");
        gotoxy(37, 14); printf("ID: %i", *starray[0].id);
        gotoxy(37, 16); printf("Name: %s", starray[0].name);
        gotoxy(37, 18); printf("Term: %d", starray[0].term);
        gotoxy(37, 20); printf("Score %: %0.1f", starray[0].gpa);
        gotoxy(37, 22); printf("GPA: %c", starray[0].grade);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 300: The file pointer is at EOF when that line is reached because of lines 277-288: there is no need for that loop so just delete it. Besides, there is a lot easier way to get the number of characters in the file. But that function doesn't need to know how big the file is.

After making the changes I mentioned, that function should look like this:

void sortstudents()
{
    clearWindow();
    FILE *fp;
    fp = fopen("record.txt", "r");


    //stud *arr = (stud *)malloc(chunck);
    stud starray[25];

    int count = fread(starray, sizeof(stu), 100, fp);
    fclose(fp);


}

Note that the array is local to that function, so it will get destroyed immediately when the function terminates. If you need the sorted array somewhere else in your program then you will have to pass it as a parameter into the function instead of declaring it locally.

The next think I suppose you need to do is sort the array. There are a lot of sort algorithms, some more difficult than the others. I'd suggest you use the bubble sort algorithm becaue it's the easiest to code. You can easily find it by googling for "bubble sort algorithm".

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

You'll get better answers if you post in the corrct forum instead of just posting in any random forum that suits your fancy. Would you go to a butcher to ask a question about fixing your car? He may or may not know the answer, but it would seem more reasonable to go to a mechanic for that kind of question.

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

The while loop beginning on line 28 needs brackets { and } because there are more than one statement within the loop

You don't need the if statement on line 26, so you can just delete that line.

  while(konduktor->p_next_num !=0)
  {
      cout << konduktor->num;
      konduktor = konduktor->p_next_num;
  }         

Now, to answer your question. When the loop on line 28 finishes the konduktor pointer is at the end of the linked list. Just allocate a new structure the same way you did on lines 18-23, but this time use konduktor->p_next_num pointer instead of head_of_list pointer.

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

How did you write the records? Did you use fwrite()? If you did, then just use fread(). The parameters to fread() are the same as fwrite()

struct student students[100];
int count = 0;

while( fread(&students[count],sizeof(struct student),1,fp) == 1 )
   count++;

// Another way of doing it is to attempt to read them all at one time
// fread() will return the number of student records actually read.

count = fread(students,sizeof(struct student),100,fp);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to post a couple lines from the file so we can see how it is formatted. But generally you would want to read each field into it's appropriate structure element. The easiest way to do it is calling fscanf() instead of reading the file one character at a time like you are trying to do.

For example, it might be read something like this:

     FILE* fp = fopen("students.txt","r");
     struct student st;
     struct student starray[100];
     int numStudents = 0;

     while( fscanf(fp,"%s%s%d%f%c",st.id,st.name,&st.term,&st,gpa,&st.grade) > 0)
     {
          starray[numStudents++] = st;
     }

But, of course, the above may be all wrong, depending on how the file was written.

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

This is C# forum, not java. For java questions post in the java forum. And ... do not hijack someone else's thread to ask your question but start your own thread.

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

I have both windows 8.1 and windows 7 on the same homegroup network and they each share printers and folders with each other. Most are wired, but one is wifi.

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

Before comparing a pointer to NULL you have to initialize them to null when you declare the pointers (or at least some time before using them). If you don't then the the value of those pointers are whatever happens to be in memory at the time they are declared, which may or may not be 0.

char *strings[100] = {0};

The above will set all 100 pointers to NULL (which is the same as 0)

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

Are we ever able to make a program that can speak like a human ?

Just ask Lieutenant Commander Data from Star Trek or the darleks from Dr. Who :)

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

the value of SIzE is 4, the initial value of counter is 0. So SIZE never equals (counter+1). The value of counter never changes inside the loop.

how is the right way to do it?

Increment counter somewhere inside the loop but outside the if statement, most likely place is on line 4.

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

It looks like main() is calling the wrong function. insertIntoTable() instead of insertValuel()

IMO insertValue() is too complicated, paramitizing the sql like that is not necessary.

sprintf(sql,"INSERT INTO table(id,text) VALUES(%d,\"%s\")",1,randomText.c_str());

Now with that simple line call sqlite3_exec(), as shown in this 5-minute tutorial.

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

How do you think data is going to be put into the clipboard? Some process other than your program has to do it, it's not possible for someone enter clipboard data from the keyboard. Sleep() will allow other programs to run and possibly store data into the clipboard so that your program can see it. And since you have no control over what other programs do your program might have to wait an awful long time before another process puts something into the clipboard.

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

Thanks for doing his homework for him.

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

How do you expect the thread to wait until it does something? You can't have it both ways.

What's supposed to happen when GetClipboardData() returns NULL? You need to put a Sleep() in that loop so that other processes and threads get CPU time.

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

person.name[i]

You need to index person, not name

person[i].name

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

In a M by N array, where M is the number of rows and N is the number of columns, the array has these coordinates

Upper left: 0,0
Lower left: (M-1),0
Upper Right: 0,(N-1)
Lower Right: (M-1),(N-1)

The way I understand your assignment is to find the sum of those four cells.

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

line 11: remove all the spaces.

haider885 commented: thanks....its working now +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No, I will not solve it for you, but we will help you solve it yourself. Post some code that you have started so we can see where you need help.

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

One would think that one would not want to sound pretentious, now would one? :)

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

yes. If you want it in another thread then you have to specifically create a new thread, then start a new instance of the class from within that new thread. New threads are never ever started all by themselves, you have to do it yourself.

Read this article and this about how to create a thread.

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

Your options are somewhat limited, but here is an ODBC tutorial

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

It runs in the curreent thread.

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

I did this and it still works ok

    char* result;
    while( (result = fgets(line, sizeof(line), fp)) != NULL)
    {
        puts(result);
        char* token = strtok(line, " ");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can usually find online help with most c++ functions and classes by googlein for them. In this case, google for "c++ std::string" and this will be the first hit you see.

Once there, click the link (constructor)

Next, look down the page at Parameters and you will find this (where n is the first parameter and c is the second):

n
Number of characters to copy.
c
Character to fill the string with. Each of the n characters in the string will be initialized to a copy of this value.

In otherwords, line 14 is creating a std::string object of 1 character and initializing it with whatever *being points to.

lines 19-22 loops through the rest of begin, but to me that loop isn't doing much of anything. I don't see any purpose of that loop.

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

calloc is the same as malloc but calloc initializes the memory to all 0s

Both these are the same

int *array = malloc(10 * sizeof(int));
for(int i = 0; i < 10; i++)
   array[i] = 0;


 The above can be rewritten with this one line:

 int *array = calloc(10, sizeof(int));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Nothing wrong with fgets()

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996)

int main()
{
    char line[126];
    FILE* fp = fopen("TextFile.txt","r");
    if (fp == NULL)
    {
        puts("Can't open the file");
        return 1;
    }
    while( fgets(line, sizeof(line), fp) != NULL)
    {
        char* token = strtok(line, " ");
        if( strcmp(token,"Client:") == 0)
        {
            puts("CLIENT");
            while (token != NULL)
            {
                puts(token);
                token = strtok(NULL, " ");
            }
         }
    }

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

You must be doing something else wrong. This works ok for me

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable: 4996)

int main()
{
    char line [] = "Client: z q";
    char* token = strtok(line, " ");
    if( strcmp(token,"Client:") == 0)
    {
        puts("CLIENT");
        while (token != NULL)
        {
            puts(token);
            token = strtok(NULL, " ");
        }
    }

}

And the console display is this:

CLIENT
Client:
z
q
Press any key to continue . . .

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

post the line that was read from the file. If the program doesn't print "CLIENT" like you had on line 16 then my guess is the line in the file doesn't contain the word "Client" at the beginning -- remember capitalization is important, so Client and client and client: are not the same.

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

line 17 the first parameter to strtok() should be NULL, because it's alredy been called with line as the first parameter on line 12.

if( strcmp(token,"Client:") == 0)
{
    printf("CLIENT\n");
    token = strtok(NULL, " ");
    while (token != NULL) {
        puts(token);
        token = strtok(NULL, " ");
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, it works something like that. Example:

char line[] = "one two three 123 456";

char* ptr = strtok(line," ")
while( ptr != NULL)
{
   puts(ptr);
   ptr = strtok(NULL," ");
}

The first time strtok is called with a charater array. After that, the first parameter to strtok() is NULL. It will return NULL then the last token has been read, normally meaning end-of-data.