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

line 9: num.length(x) num is an integer so it doesn't have methods like length. perhaps you meant number.length() -- note that length() does not take any parameters.

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

you need to make more generous use of { and }

void blur(int src[], int rows, int cols, int dest[]) {
	int count;
for (int i = 0; i<rows; i++) 
{
    for (int j = 0; j<cols; j++)
    {
          for (int count = 4; count <= i*cols + j; count++)
          {
               int sum[i*j];
               sum += src[count];
              dest = sum / count;
         }
    }
}

line 19 above:
(1) you can't declare an array like that because i*j must be a constant. If you want to use variables then you have to allocate the array with either new or malloc().
(2) Why are you declaring that array inside that loop??? Move the declaration up probably above line 3.
line 10: the previous line 9 declares sum as an array, but line 10 attempts to use it as a simple integer. You can't have it both ways.

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

You'll have to explain a little better because I don't see the problems you report.

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

>> Is the above correct?
Looks ok to me, assuming you have declared all those variables correctly.

>>It's taken from the online book "Numerical Recipes in C
Don't make the mistake of assuming all books are 100% correct. They aren't, I have found lots of misprints in them. Check the author's or the printer's web site to see if they have corrections, most have corrected code that you can download.

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

>>i did not want to ressurect old threads.
Good -- you might have teen tounglashed had you done that :)

Write a function that keeps track of all the random numbers it creates. Put the numbers into an array then each time a number is generated search the array to see how many times that number has been generated. You want the numbers 1-12 then create an int array of 12 elements and initialize them to zero. If you generate the number 2 then you will increment the 2nd element of the array -- array[1] is the 2nd array element.

int array[12] = {0};
..
int gennum()
{
   while(1)
   {
        int n = rand() % 12 + 1;
        if( array[n-1] < 4)
        {
            array[n-1]++;
            return n;
        }
  
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So you are using *nix? In that case you don't need process.h. The system() function is declared in stdlib.h. Read this man page.

<<When I run this code with long names it gives me an infinite loop:
Because that while loop has no way to stop. How does bFinish1 every get set to some value > 0 so that the loop will terminate ?

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

You didn't even try, did you ???
See these threads

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

>>Can anyone help me that how to develop the codes.

Sure thing -- start here

#include <stdio.h>

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

>>Can you please help me with the function call?
What about it that you don't understand ? All you have to do is pass the variable names estimate(data, n, m, &xms,d);

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

>> just want to know the difference at that time...
There is no difference other than what I already mentioned. Its only two different ways to code arrays. The code inside the function is identical in both cases.

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

Well, here is a quote from Goerge Bush's top evangelist.

Billy Graham is (was) probably the most respected evalangest in modern times. He didn't belong to Bush but attended to every US President since Eisenhower.

Graham has preached in person to more people around the world than anyone who has ever lived.[2] As of 1993, more than 2.5 million people had stepped forward at his crusades to "accept Jesus Christ as their personal saviour."[3] As of 2002, Graham's lifetime audience, including radio and television broadcasts, topped two billion.[2]

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

try replacing line 47 with cin.clear(); line 17: you need to add .h extension to it -- #include <process.h>

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

break jumps out of the loop but continue just jumps to the top of the loop and starts again. Before the break you need to clear the fail flag. cin.clear()

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

After some testing I come to the conclusion that it is not possible to use Ctrl+Z as you intend because the os gobbles it up and won't put it in the output string. But you can use some other Ctrl+? key such as Ctrl+A In the code below function getword() returns TRUE if the Ctrl+A key was hit during the input string or false if not.

#include <string>
#include <iostream>
using namespace std;
const int endofinput = 0x01;

bool getword(string & word)
{
    char c;
    bool ctrlZ = false;
    do {
        cin.read(&c, 1);
        if( c != endofinput)
            word += c;
        else
            ctrlZ = true;
    } while( c != endofinput && !isspace(c));
    return ctrlZ ;
}
int main(void)
{
    string word = "";
    while( getword(word) != endofinput)
    {
            cout << " " << word;
    }
    
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How i can solve it?
By adding the library to the link statement. How to do that depends on the compiler you are using and possibly the makefile.

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

>>then what is the difference between both styles ??
The first is most definitely an array. The second may or may may not be an array because it could also be a pointer to a single int object. function() must be made smart enough to know whether *p is a pointer to an object or an array. In both versions of the function it must also know how many elements are in the array.

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

If you are using palm OS the you must know that it doesn't support stdout like desktop programs do. I've written for PocketPC and Mobile 5 os for the past 8 years or so writing MFC applications using eVC++ 3.0, eVC++ 4.0 and VC++ 2005 compilers. MFC itself is not fully supported on those operating systems. But I'm assuming you have already found that out.

>>But, would you happen to know of an any alternative methods for this?
NO I don't know of any way to do what you want to do on that os.

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

Threads are not natively supported by the c++ language but there are several api functions and libraries that you can use. One of them is win32 api function CreateThread()

Also see this thread

[edit]^^^ Tracey's example is excellent too.[/edit]

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

>> I'm getting just 2 errors, a missing ";" before the main
Look at that line just before main(). Don't you see anything wrong with it ????

>>"unexpected end of file" at the main definition
You have a ton of errors in that program, other than the problem ^^^ above. Fix above problem, recompile and you will get millions of other errors. Fix only the first one, recompile then repeat until all problems are resolved.

For example:

double data[] = 
{
//Loads(~1000) of data vavues between +1 and -1. Ex: -0.15709, -0.25413,...
};

You can't leave that like that. The array must have at least 1 element in it. If you don't know how many to allocate then just make up something for now double data[1000] = {0};

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

test for ^Z before writing to the file

if( word != "^Z")
   cout << " " << word;

Also not that "^Z" (which is 2 characters) is not the same as '^Z' (which is only 1 character that you generate by hitting the Ctl key plus Z key at the same time, or Ctrl+Z. And that is the usual way to terminate an input other than by the <Enter> key.

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

swapping character arrays can not be done with the = operator. Instead you have to call strcpy() to copy them.

strcpy(cExtraName,cRunner1);
strcpy(cRunner1, cRunner2)
strcpy(cRunner2, cExtraName);

As for your first problem you will have to post all the code so that we can find the problem. If you don't want to do that then search for the problem somewhere before that getline().

Also, when you swap the name you also have to swap the runtime so that the names and runtimes say in the same order.

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

>>q2: I am also having having trouble convert a int to a string and i looked it up but i am >>not sure how to use itoa or sprintf

This is c++, so don't use either itoa or sprintf. Use stringstream instead

#include <sstream>
<snip>
int main()
{
    int x = 123;
    string str;
    stringstream stream;
    // convert int to string
    stream << x;
    cout << stream.str() << "\n";
    // convert stringstream to std::string
    stream >> str;
    cout << str.c_str() << "\n";
    // convert string back to int
    stream >> x;
    cout << x << "\n";
}
Crazycfk commented: gave great information to troubling question and provided a code to help with the problem +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just tried it and all I had to do after deleting the *.cpp and *.h files from the file system and deleting them out of the workspace was select menu item Build --> Rebuild All.

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

try deleting all the *.obj and *.pch files then recompile everything.

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

To delete a file -- remove(const char* filename);

string filename = "Hello.txt";
remove(filename.c_str());

rename a file

string original_filename = "temp.txt";
string new_filename = "Hello.txt";
rename( original_filename.c_str(), new_filename.c_str());

Now put those two code snippes together and you have the problem solved.

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

You don't read very well do you. Re-read my post #45 because I explained how to do that. You can not write directly to the existing file but you have to write to a new file.

I suppose you could write to the existing file instead of a new by if you read the entire file into one big buffer or linked list of lines, change the data in memory, close the input file, open the file for output so that its contents are truncated, then finally write all the in-memory lines out to the file.

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

>>I don't know what to write to achieve this
That's not the only thing you don't know how to write. Your program is littered with tons of errors. Don't try to write that much code without compiling it firs, and fix all the errors so that the compiler does not find any errors before writing more code. It might be a lot easier to just start all over again and write only a few lines of code at a time because the code you have written is going to be difficult for you to correct.

Examples: lines 14 and 15 won't compile because m was never declared. And function main() is missing braces { and }.

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

you have already written code similar to that. Open a new file for output and write to it exactly like you did when you changed all the characters in the file to upper case.

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

No, all you have to do is tell the linker that it should use that library. There are several ways to do that but the easiest way is to add this near the top of the *.cpp file

#pragma message(lib, "ws2_32.lib");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can u write for me this code....cuz really i'm obviously stuck in that case.

After all the code you have written in this program you still don't know how to create a loop and change each character in the string? Astonishing!

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

Functions writtein in C language can be called by almost every other language. For example: most, if not all, the win32 api functions for MS-Windows operating system were written in C language and some assembly. Yet all these functions can be called by every other existing language such as Visual Basic, assembly, pascal, cobol, C#, fortran, etc.

why its ideal for engineering solutions -- I have no idea because I never took an engineering course.

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

You can redirect the console app's output to your dialog box as described in the links I posted.

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

>>Any Idea why this section of code would give me these linker errors
Yes. You have to add Use Ws2_32.lib as described in the Requirements section here

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

It is never too late to learn something new. Ever. It is a dangerous mindset to get into to think that it is "too late" to do something.

True but that's not the issue here. I think the issue is -- is it too late for him to enter into the IT field as a newbe? Can he get an entry-level job ?

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

The problem you are experience has nothing to do with the compiler but due to your program. If you use cin to get an integer it leaves the <Enter> key '\n' in the keyboard buffer, so you have to remove it before moving on in the program

int x;
cin >> x;
cin.ignore()

If you do that then the cin.get() at the end will work. Again, its your program, not the compiler.

>>the free-ware is so dreary but better than nothing
I don't care much for that compiler either and I like VC++ 2008 Express a lot better -- and its free too. But for portability between *nix and Windows Dev-C++ is the better compiler.

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

Yes, thanks Narue. I didn't notice that Advance link probably because its a little difficult to see due to the contrasting colors.

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

hey Ancient Dragon, thanx for ur new information can you plz tel watz that fourth argument used in main funtion in Mac environment...........
thanx in advance

read the link I posted. Other than that I don't know because I've never coded for MAC

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

You are not validating the return value of strtok(). It returns NULL if its at the end of the string when you call strtok() with a NULL first parameter (or some other error occurred). It would be more prudent to code it like this:

char* ptr;
while(fgets(b2b_rates_address,1000,in_fp) != NULL )
{
     if( (ptr = strtok(b2b_rates_address,","))
     {
            strcpy(rates_details[j].ig1, ptr);
            printf("rates_details[j].ig7 = %s\n",rates_details[j].ig1 );
            if( (ptr = strtok(NULL,",") )
            {
                  strcpy(rates_details[j].ig2,ptr);
                  printf("rates_details[j].ig7 = %s\n",rates_details[j].ig2 );
                  if( (ptr = strtok(NULL, ","))
                  {
                      strcpy(rates_details[j].ig3, ptr);
                      printf("rates_details[j].ig7 = %s\n",rates_details[j].ig3 );
                   }
           }
     }
     j++;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the code on this dev C++ the output does not stand still it just flashes and disappear
You have to add getch() or something like that at the end to make it stop so that you can see the output.

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

Would it be possible to limit the searches to a specific forum, such as just the forum I happen to be viewing at the time ?

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

hey dudes there are three ways to declare main function
1>int main () {}
2>int main (int argc, char *argv[]) {}
3>int main (int argc, char *argv[], char *arge[]) {}


***arge argument is used for environment variables......

Sorry but the third argument is non-standard by some compilers. MAC even has a fourth argument. Here is a good article about this.

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

getch() is a non-standard function by Borland therefore not all compilers support it.

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

You need a game engine such as DirectX SDK (free for the downloading from Microsoft). But be prepared for some very heavy-duty c and c++ coding. The SDK that you download includes quite a few example program to illustrate how to use the SDK.

Also check out the Game Development board.

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

If you want 20 characters then iLength = 21 is correct. getline() will insure that no more than 20 characers are put into the input buffer.

If you change to using c++ std::string then you don't have to worry about the length at all because std::string will expand to fit however many characters are typed from the keyboard (I think there is a limit of 32,525 or something like that, but I hardly doubt anyone is going to type that many charcters.)

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

The problem I see is that the loop will need to be in a different thread than the buttons so that the loop and the buttons can run independently of each other. If they are all in the same thread then you can't press either button while the loop is executing. Once you put the loop in another thread you can create a global flag to indicate when to execute and pause the loop

For the below to work, Button1 will set the value of the flag to true and Button2 will set it to false.

bool flag = false;
for(int i = 0; i < 1000000; i++)
{
    while( flag == true)
    {
        Sleep(1000); // one second delay
    }
    // do something here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can put something in an if statement

for ( int i = 0; i < 100000; i++ )
{
	i = i + 1;
          if( i == 50000 )
         {
             cout << "Press Enter to continue ...";
             cin.get();
          }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> would like to put the last two lines in a While Loop to prevent the user from going over >>the 20 character limit,

When you use getline() that isn't necessary because getline() will no accept more than iLength number of characters including the string null terminator.

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

I think the Reverend Wright's serman backfired on him and caused more harm to Obama's candidacy than Hillary Clinton did in the previous year of campaigning. There are now many Americans and superdelegages who are now questioning Obama's ability to win an election in November.