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

sizeof(int*) returns the size of a pointer, while sizeof(int) returns the size of an integer -- the two are NOT the same. And the lines you quoted are not the same either. Example: assume nrows = 10, ncols = 5 and sizeof(int) = 4. The first equation is 10 * 5 * 4 = 10 * 20 = 200. The second equation assume sizeof(int*) = 4, then 10 * 4 = 40. Clearly the two equations do not result in the same value.

Another way to look at those two code snippets you posted: the first allocates memory for a two dimensional array of integers while the second allocates memory for a one dimensional array of pointers.

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

do it the same way as you would with cout to print to the console fout << "Hello World\n"; . The syntax is identical to cout. Then close the file fout.close(); before calling your showFile() function so that everything gets physically written to the disk.

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

Did you create a DLL project when you got to the window that listed all the different project types? I did, then tried to compile what Dev-C++ generated and got an error that the linker can not find dllcrt0.o even though its in the lib directory. I'm trying to find the solution to this problem.

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

doesn't matter what compiler you use. If you want to write a DLL then you need to create all those files as shown in the tutorial.

To start the DLL project select menu File --> New --> Project then select the DLL icon.

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

Dev-C++ and Microsoft VC++ 6.0 (rarly any more) and VC++ 2005 Express.

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

You created the wrong kind of project. To create a console project, select menu File --> New --> Project --> then select the Console Application icon.

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

nevermind. I misunderstood the previous post.

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

Use the clock() function. Create a loop and display the next character in the string when the current value of clock minus the original value is >= 25

clock_t t1, t2;
t1 = clock();
while more characters to display
    if  clock() - t1 > 25
           display a character
           set t1 = clock()
    end if
end loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char *string2[100][4];
That is not the same as in the function prototypes. char * is a single one dimensional array, what you have created is a three-dimensional array. The two are not compatible. What I think you want is this: char string2[100][4]; which is a two-dimensional array, and the function prototype would look like this: void view(char string2[100][4], int * inv, fstream& hardware); >>int *inv = 0;
That is a pointer that points to nowhere. Yet you are passing it to the functions and those functions are attempting to dereference address 0. That might well compile without complaint, but at runtime your program will crash and burn big time. What you are supposed to pass is a pointer to an integer.

int inv = 0;
...
view(string2, &inv, hardware);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since my eyesight is too poor to see your monitor I am unable to help you any more that that. Post more code so that someone can see what you are doing.

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

>>What I'm wondering is that how come it matters which specific bit is turned on or off? And where would it be implemented in everyday use programs?

Its often used to pack booleans in one integer. Suppose you are working with several led lights attached to a serial port and you need your program to know if a specific light is on or off. One way would be to define a bool flag for each light. But a more efficient way would be to bitmap and integer. The program could use the '&' operator with a mask to check if the light is on or off.

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

>>edit(string2[100][4], (int*) inv, fstream* hardware);
That line is wrong -- don't put the data types in that line, they only go in the function prototypes and function header, should be this: edit(string2, inv, hardware); . You need to correct the line that calls view too.

Also don't confuse the address operator '&' and the reference operator '&'. The reference operator is used in function prototypes and function declarations to tell the compiler that the parameter is a c++ reference to some object. The address operator is used when calling a function to create a pointer to the object. The two are similar but not the same thing.

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

You can pass it as a parameter to the functions that need it. And pass it by reference, not by value void edit(char *string2[100][4], int * inv, fstream& hardware)

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

>>'hardware' : undeclared identifier
where did no define hardware ? You can ignore that second error message because it is related to the first one.

>>Is there a better way to do this?
Fix the error?

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

Yes, see this thread . Just change your compare function as shown in that thread.

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

>>I want to change every comma to a zero?
You can not do that -- the const keyword means the string can not be changed. All you can do is increment the pointer and look at the contents. If you want to change the string then copy it to another char buffer. After copying the string then you can do this to change it

if( *ptr == ',')
    *ptr = '0';

where ptr is a pointer to the copy of the string.

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

just declare another pointer to be the same as the original and increment it until it reaches the end of the string. Along the way count the number of commas etc. You could use the original pointer but its better not to so that you don't destroy the address of the original string.

const char* original = "bad,cold,new";
char *dup = original;
...
...
if( *dup == ',')
{
//   do something
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 26: eof() doesn't work like that. Use this instead

while( inFile >> name >> points >> description )
{
   // blabla
}

But that assumes each line contains exactly three words with no embedded spaces. For example it won't read a name such as "John Smith" correctly.

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

>>I do't have a project folder (anyway i do't understand what this mean).
The project folder is the directory where you saved the C or C++ files. I hope you are not dumb enough to put them in the root directory of your computer.

In pure win32 api programs there are no files with standard numbers like ID_FILE_EXIT. You can use any numbers you want because they are only used in your program.

If you are writing an MFC program you will find the declarations in afxres.h which is located in your compiler's include directory. And in MFC its ID_FILE_CLOSE not ID_FILE_EXIT.

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

There are lots of free compilers. But I don't know if any of them have VB-style wizards to generate windows code.

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

I agree, but it isn't free, so that's why I didn't recommend it.

Niek

Oh so you recommended something the OP can't use because its free?

Nick Evan commented: Whoops, sorry 'bout that +3
Jishnu commented: Well said!! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes VC++ 2005 Express is free but it does not contain a code wizard that generates GUI code other than a bare shell with pure win32 api functions. It doesn't let you work with windows like VB does. If you want VB type wizards then Borland C++ builder is probably the best c++ tool.

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

Are you writing a windows GUI program? If yes, then you put all those numbers in resource.h file.

>And where i can find all of this?
The resource.h file in your programs project folder

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

line 6: do you have a program on your computer called command.exe ? If not then that line of code will do nothing other than get an error message from the operating system that "command not found".

lines 8 and 10: that loop doesn't work right. You need to combine them like this:

while( file_op.getline(str,5000) )
{
    // compare the strings here to see if this line is the one you are looking for
}

line 13: you can not compare two c-style character arrays like that. Use strcpy() to do that if( strcpy(errorline, str) == 0)

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

>>qsort(array[c], length, sizeof(int), compare);
that is incorrect. You are sorting an array of char pointers not an array of integers qsort(array, c, sizeof(char*), compare); Your compare function is also wrong. Why are you converting the char pointers to integers? I thought the strings are words? All you need is this?

int compare(const void* pnum1, const void *pnum2)
{
    return strcmp((char*)pnum1, (char*)pnum2);
}

for (i = 0; i < length; i++)
{
cout << array << endl;
}

wrong there too. length is the number of characters in the original string. What you want here is variable c, which is the number of valid pointers in array

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

>>and compiling c/c++ programs from my mobile phone
Forget it. Mobile phone don't have enough memory or disk space. It needs about 400 meg RAM and about 20 gigs hard drive (depending on the compiler, some more and some less). Even if there were such a thing it would be too slow to be of any value. Get a normal PC or notebook and use that for your programming.

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

>>from my mobile phone
Do you really mean you want to write a progrm for your mobile phone? I know of no compiler that runs on a mobile phone. You will first have to find out what operating system it is running. Is it Microsoft Mobile 5.0 or something else. If its Mobile 5.0 then you will need Microsoft VC++ 2005 Pro edition -- the free Express edition doesn't support writing mobile programs. PocketPC and Smartphone are also Microsoft operating systems and you can get a free compiler from Microsoft for them -- eVC++ 4.0

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

you have too many = symbols -- its == and !=

the loop at lines 18-22 isn't going to work. Move line 20 to after line 13 then delete the rest of the loop at lines 18-22. Another way to code it is like this:

bool done = false;
while( done == false)
{
    for (int buddynum = 0; buddynum < 3; buddynum++)
    {
         cin >> newinput;
         friends[buddynum] = newinput;
    }
    if (mystery[0] == friends[0] || mystery[1] == friends[1])
    {
          cout << "You guessed right!";
          done = true;
    }

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

Put lines 10 thru 19 in another loop and break out of the loop if the user guessed right.

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

you will need to store the pointers that are returned by strtok() in an array of pointers so that the words can be sorted by qsort.

char* array[255] = {0}; // assume max of 255 pointers
...
int c = 0; // arrays start at index 0, not 1
while (token != NULL)
{
    cout << "token " << c << " is " << endl << token << endl;
    array[c] = token;
    token = strtok(NULL,delim);
    c++;
}

Now after that you can use qsort to sort the array of pointers.

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

you need an ifstream object to open the text file, and a string to receive the strings. Both of these are standard c++ classes in <fstream> and <string> header files. There are hundreds, if not thousands, of examples you can follow to write your program so I am not going to repeat them here. Basically you need to (1) read a line using getline function then (2) compare it to the string you are looing for using the == comparison operator.

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

>>what is the best way to sort all strings in arrPP
Declare them all in one big array and in sorted order then you won't have to worry about that.

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

I think you need to get a newer compiler that supports current c++. Dev-C++ is free and used by many people. Also VC++ 2005 Express is free and actually a better compiler, but a little more difficult to learn how to use. There are several other compilers too.

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

Try reading the Read Me threads at the beginning of this board. And stop using all caps because its considered very rude to shout at us.

>>and it still showed quite some errors
Can't help you if you don't post the exact error message(s)

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

You probably need to read this

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

I think you would get quicker and probably better advice from Oracle's forum boards that specialize in Pro*C SQL language.

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

I just compiled it ok, but I put printAllStrings() at the top of the file before main()

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

why don't you just use getline() to input the sentence instead of that more complicated use of get().

cin.getline(sentence,sizeof(sentence));
letters = strlen(sentence);

Now you will probably have to use a structure of letter number and frequency so that you can sort the structures by frequency while maintaining the relationship with its letter value

struct frequency
{
    char letter;
    int count;
};
vector<frequency> counters;

At this point you have to iterate through sentence, search counters array for the current letter. If not found then add one to the array otherwise if found just increment the count for that letter.

Here is how to sort a vector

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

>>I'm still gettin fopens deprecated though
That's only a Microsoft thingy -- C and C++ standards make no such claim. You can use a pragma to disable that warning #pragma warning(disable: xxxx) just replace the x's with the warning number.

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

>>I'm sure it's what I need but I don't really understand how strstr works
Very simple -- it searches through the string in the first parameter for the first occurrence of the string in the second parameter. If the first string contains the second string then strstr() will return a pointer to the start of that string. If it is not found then strstr() will return NULL.

Example:

strstr("Hello World", "is"); // return NULL because "Hello World" does not contain the word "is"

strstr("Hello World", "orld"); // will return something other than NULL because "Hello World" does contain the string "orld". Note that this does not have to be an entire word but any sequence of characters.

If you want to use command-line arguments where the first argument is a filename and the seocnd argument is the string you want to find, to modify Narue's code a bit

int line_number = 0;
FILE* in = fopen(argv[1],"r");
while ( fgets ( line, sizeof line, in ) != NULL ) {
  ++line_number;

  if ( strstr ( line, argv[2] ) != NULL ) {
    printf ( "%d: %s", line_number, line );
    fflush ( stdout );
  }
}

>>I feel like I need more substance in my main to make it work
I think you are trying to make a mountain out of a mole hill :)

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

We have already given you some hints. Now start studying your textbook from page 1 and don't skip ahead. You have to do some studying on your own.

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

>>I've missed my classes and tried to read some tutorials but it's too damn confusing
Well, how about reading your textbook for the class you are taking ?

>>but it's too damn confusing
Yes I agree it is confusing at start. I felt that way too when I first started. Hang in there and keep reading because it will come to you eventually.


Here is the beginning

#include <iostream>
using namespace std;

int main()
{
   // your code goes here
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

methods of a class are never ever on the stack -- only data objects go there.

int main()
{
    Foo f; // object f goes on the stack, but not the methods of that object.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>If some one can do this please post the code, I'd be trully grateful.
I'm sure you would be grateful, but doing yourself disservice by not doing it yourself. We will NOT do your homework for you. Post the code that you can do and ask questions about what you can not do.

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

>>and i cammot figure out why.
Because you told it to print it on line 82. Delete that line and it will be ok.

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

It is a lot easier to sort the data if you should create a structure to hold the information for one city then create an array of those structures.

>>strcmp not liking the strings.
Yes, strcmp() wants char*, not strings. If you using string objects then you can pass method c_str() to strcmp().

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

What is that? [a.out]

The default name of the executable when using *nix compilers is a.out. Don't know why but probably just the custom by now.

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

line 30: modf() takes pointers to two doubles. value is not a double. And it returns a double, not an integer. Please read the documentation for functions you use.

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

line 16: semicolon is missing at end of the line.