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

>>The issue is that I cannot be certain that the length of str1 is enough to hold both str1 and str2.

And there is no way to do that in C language. C language lets the programmer do a lot of things that are potentially harmful to the program, and buffer overruns are just one of them. There is no way to determine how much memory was allocated to a pointer, or if any memory was allocated at all. There are several ways to crash strcat(), insufficient memory for destination string is just one of them. Another way is pass a string literal as the destination string, such as strcat("Hello","World"); is a guaranteed way to trash memory. And a couple little more subtle ways to trash memory

char* destination = "Hello";
strcat(destination,"World");
void foo(char* dest, char*source)
{
   strcat(dest,source);
}

int main()
{
   foo("Hello","World");
}
dotancohen commented: thank you, I will remember your word when I get to pointers +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sounds like Ron Paul's a winner to me, but that's not likely to happen.

>>P.S. What happened to the bad word filter?
The word "shit" is not considered a bad word -- daytime American tv rule.

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

%i = integer, but its the same as %d
%u = unsigned integer

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

This isn't rocket science either. As Walt said you need to post what you did -- the complete program.

>>However , it fails.
What fails? Compiler gives you errors? Or GetConsoleWindow() fails to return a valid HWND pointer?

Also tell us the compiler you are using.

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

Well, its only the two functions I posted. I gave you the links, just read them to see how they are called. Yes I could easily write the code for you, but you will learn a lot more if you read and study those links yourself. Just include windows.h header file.

Salem commented: Yes! +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you are using CLR/C++ (managed code) instead of just c++ you should be calling System.IO.FileSystemInfo's GetAttributes instead of the win32 api function GetFileAttributesEx().

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

Assuming this is a console program on MS-Windows operating system.
1. call GetComnsoleWindow() to get the HWND of the window

2. call GetWindowRect() to get the RECT structure that contains the window's size.

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

Not all the values between 0 and 255 have printable ascii values. The only printable ascii values are between 32 (a space) and 126 (the dash - ). All the values outside that range will just print nothing, squares, or other seemingly random garbage. See this ascii chart for all the values.

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

Here are a few tutorials you might want to review.

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

Your first code snippet is not acceptable on any standard version of C. However some old compilers, probably Turbo C, might accept it. C and C++ languages both require main() to always return int.

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

Make sure you understand what FunctionA() is going to do with that BSTR. If you allocate the memory like in my second code snippet and FunctionA() reallocates it then that will result in a memory leak.

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

Did you calculate the amount of memory that program takes? 15000*100*sizeof(float) is the number of bytes need for just one of those arrays.

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

BSTR is already a pointer, so BSTR* is like writing char**. FunctionA() only needs BSTR* if it plans to allocate the memory for the variable declared in the calling function.

Here is a good explanation of how BSTR works. Scroll down the page and it will show you how to allocate the memory for the BSTR by using SysAllocString(), also that is not the only function that can be used for that purpose.

If you do not have control over how FunctionA() is declared (such as it is a library function that you don't have the source code) then you would pass the BSTR like this:

void Caller()
{
    BSTR pbstr;
    FunctionA(&pbstr);
}

The above assumes FunctionA() is going to allocate memory for the BSTR. If, on the otherhand, FunctionA() expects the BSTR to already be initialized with some string or data, then do something like this:

void Caller()
{
    BSTR pbstr = SysAllocString(L"Hello World");
    FunctionA(&pbstr);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 26: does N_row contain a valid value?

I don't see how the code you posted could cause a stack problem since it doesn't appear to be using any arrays. The real problem could be somewhere else in your program, but its just manifesting itself in the code you posted. You would have to give us the entire program in order for us to help you debug it. If its a large project then just compress it and attach it to your post. But if the code is proprietary, such as company secrets, then its best not to do that.

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

You don't need that chr1 declared on line 10. Why save the input characters? Just read a character from the file and process it.

line 17: sentences also end in ? and ! characters.

line 20: you need to increment the number of characters count for each character read in from the file, not just the number of spaces. Delete lines 20 and 22, leaving only chars = chars + 1.

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

I would like to see Dani apply those same rules over on PFO. There currently are no rules against sig only spamming, so many of them are not deleted, although I must admit to deleting them anyway in some cases. For example I'll delete "nice post, thanks for sharing" type posts even though there are no rules forbidding it.

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

Start out very simple by counting the number of letters in a sentence. When you get that finished and tested then you can write the code to count the number of words. Do just one part of it at a time so that you don't get overwhelmed by the complexity. You will need integers to contain the counts and a loop to inspect each character of the string.

Write the code to count letters, then post what you have written and feel free to ask specific questions about what you don't understand.

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

I was under the impression that there was a cap function that came with the language when using the appropriate header file & that he had wanted me to invoke it.

There is -- its called toupper() but it only converts a single character and you have to tell it which character to convert. Otherwise, there is no such standard function in the C or C++ languages.

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

You will have to check each character to find the spaces and/or tabs, then convert the next non-white-space character to upper case (there could be more than one white-space characters between words). You have to use a loop to do that.

As for toupper(), check your compiler to see if it supports it. Almost all C compilers do. Don't know about Turbo C but I suspect it does too.

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

>>n_itr*=sizeof(char);

Not needed. The C/C++ standard guarantee that sizeof(char) is always 1. so that statement is merely multiplying n_itr by 1, which is nonsense.

And what is that string class you posted? Are you referring to std::string? If yes, then it has no arr data and that makes your complete post nonsense.

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

google is your best bet. But very old software may no longer be available. Check out shareware and freeware sites (google for them)

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

That will not create an MS-World document file, but just a plain text file. The *.doc file is normally MS-Word file format, not text file format. Don't confuse people by naming file with incorrect or non-standrd extensions.

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

my progrms don't run
what i do?

Simple. Fix it.

NathanOliver commented: that normaly will do it +9
jingda commented: Short and sweet +9
kvprajapati commented: :) +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If I wanted a lecture in jihad appeasement from the politically correct, I would have requested one. I'm not interested in discussing the issues. Maybe one of the members has the guts to offer up something on the requested subject.

Your the one who started this crappy thread, so don't complain when someone posts something you don't like. But I would agree this thread should be closed to agoing religious flame war.

happygeek commented: nicely put AD +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And note you have to include windows.h in order to use Sleep()

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

>>Oh and can assembly be compiled with C? Like if I felt like using assembly on a certain part of a C program I could?

Depends on the C compiler. If your C compiler lets you do it then its an extension of C language. Different compilers have different ways of letting you embed assembly inside a c program. That's because assembly is totally non-portable, so if you use it then you will be unable to port the program from one processor type to another without rewriting the assembly code.

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

Generally speaking, I believe main is used when the application is compiled using the console subsystem and WinMain is used when compiled using the Windows subsystem.

I suggest searching for "WinMain vs. Main". That should pull up some results for you.

Although that is true in general, the question was: what is the significance of one over the over in OpenGL programming?

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

I totally agree with what omega066 posted.

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

>>Also what is the point of WinMain anyway? Won't I be able to use windows.h without it?
Yes, windows.h is often used in console programs. I don't do OpenGL programming so I don't know the significance of using WinMain() vs main()

>> are all C libraries, standard or third party, written in assembly? I
No. They are written in C, although a few rare parts may be written in assembly.

>>C itself is just merely a 'framework' that tells what the structure of the code should be? Merely grammar, in a way.
I suppose you could think of a c compiler that way.But the language itself if much more as it contains header files and libraries of pre-compiled code as implemented by the writers of the compiler. The ANSI C language is specified by an international committee, and compiler writers such as GNU, Microsoft, Apple, and IBM each write their own implementation versions.

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

If you are using VC++ 2010 Express on MS-Windows you can step through the >> operator and find out for yourself how M$ implemented it. I tried it, and its very complicated. But have a go at it yourself if you are really interested in the internals of the >> operator.

The simplest way to convert a string of digits to binary integer is to just convert each character by subtracting '0' from the digit.

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

Does it turn it into a stringstream.. or does it just somehow use it without turning it into a stringstream? If it does turn it into a stringstream, does it mean someInt can no longer be used as an int?

The integer is NOT turned into stringstream. Instead, stringstream will contain a copy of the integer converted to string. The value of someInt is not changed and could be used later on if you wish.

stringstream always contains its data in string format. If you initialize it with an integer then stringstream will convert it into a string of the integer's digits.

int someInt = 5;
stringstream s(someInt);

//or you can do this
stringstream s;
s << someInt;

Both the above have the same results, do it either way you wish. YOu can even add other text later on s << " Hello World"; If you print that, the result will be "5 Hello World". That leads to some intersting things that you can do with stringstream in order to format a string

stringstream s;
s << "Enter " << someInt << " number of names.";
cout << s.str() << '\n';

As for the garbage value of variable c, there was an error so c was not processed. Also note that you need to add seekg() statement to move d's file pointer back to the beginning of the string before converting to an integer.

#include <iostream>
#include <sstream>
#include <string>
using std::cout;
using std::stringstream;
using std::string; …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Compile and run the program I posted but remove the virtual keyword everywhere. It will show you the difference between using virtual and not using virtual.

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

Here is one explanation. And here is another

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

what is the problem? What does it do that you don't want it to do? Does it assemble without errors? If not what are the error messages?

I can see that line 18 is a non-conditional jump which will cause an infinite loop.

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

You mean something like this? If you run this program you will see that class A is common to all the other classes. There are not separate instances of class A in class B, C and E. Any changes to the data in class A is reflected in all other classes because of the virtual keyword.

#include <iostream>
using std::cout;

class A
{
public:
    A() {x = 0;}
    void show() {cout << "x = " << x << '\n';}
protected:
    int x;
};

class B :virtual public A
{
public:
    B() {y = 0; A::x = 2;}
    void show() {cout << "y = " << y << '\n'; A::show();}
protected: 
    int y ;
};

class C :virtual public A
{
public:
    C() {z = 0; A::x = 3;}
    void show() {cout << "z = " << z << '\n'; A::show();}
protected: 
    int z ;
};
class E : virtual public B,virtual public C, virtual public A
{
public:
    E() { A::x = 4; B::y = 2;}
    void show()
    {
        B::show();
        C::show();
        A::show();
    }
};

int main()
{
    E e;
    e.show();    
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hit the "Flag Bad Post" button and ask a moderator to move it for you.

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

If that is all it is doing

double* foo(couble d1,double d2,double d3,double d4,double d5,double d6)
{
    double* d = malloc(5 * sizeof(double));
    d[0] = d1;
    d[1] = d2;
    // etc

    return d;

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

Don't put throw in constructors because that will require the calling program to put all the code that uses the class in one huge try/catch block. A better design is to have a constructor that doesn't need throw and then write another method that uses it.

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

Your program will have to read them all into memory then keep only the ones you want.

>>which function should i use

Its not a function at all. Its called an algorithm. Use ifstream to open the file as a normal text file then in a loop use >> operator to read each of the columns in each row.

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

I retired the first time when I was 42, but I couldn't imagine myself doing nothing for the rest of my life. Living in airport lounges for over 10 years would be sooooo boring.

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

Looking for running processes won't help with that problem because it doesn't tell you what the processes are doing. Launching other programs is the easy part, just a win32 api function call. Watching what other processes are doing will be a lot more complicated.

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

I don't see a problem with that at all. People ask the same questions right here at DaniWeb hundreds of times. So I don't see the significance of your comment.

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

Not possible -- DaniWeb didn't exist 10 years ago.

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

All you have to do is redirect stdout to a file. For example if the name of your program is myprog then on the command line or in a batch file myprog >myfile.txt With that, all the stuff that is printed with printf() statements will be directed into the text file instead of on the command line window.

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

Dude I'm already 23 and still not using my skills to earn some money. =/

Maybe it's time to think about moving to where the work is. I don't know where you live but you may be living in the wrong place. At 23 you should not be living with mommy and daddy.

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

You want to call CreateProcess() The function isn't nearly as bad as it looks because some of the parameters can be 0 For example

STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
memset(&sinfo,0,sizeof(STARTUPINFO));
sinfo.cb = sizeof(STARTUPINFO);
memset(&pinfo,0,sizeof(PROCESS_INFORMATION);

CreateProcess("Notepad.exe","c:\\logs\\Log.log",0,0,FALSE,0,0,0,&sinfo,&pinfo);
Graphix commented: Thank you, that did it! +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Good luck reading those header files :) I tried once to read MS-Windows implementation of iostream and gave up because it was so complicated.

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

this fixes it

void send_Message(send_request *msg)
{       
        printf("IN THIS BLOCK\n\n"); 
        msg->default_bearer.fteid = malloc(sizeof(fteid_t));
        msg->default_bearer.fteid->value = 1;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know how to do that either, but this article may be of some use.

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

You don't need lines 5, 6 and 9 because fteid is never used for anything. That is not the same as the fteid on line 8.