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

The only time \\ is needed is for string literals, like one you posted because the compiler has to interpret each of the characters in the string literal. When the path is typed in from the keyboard of read from a file the \ does not have to be escaped because the compiler will never see it. So typing the path in an edit control then coping it to a CString object can be done without escape characters.

Jsplinter commented: I see, thank you +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To convert a character from lower to upper case

char c = 'A';
cout << tolower(c);

and to convert from lower to upper, replace tolowe() with toupper(). Subtracting 32 from the character can easily lead to disaster.

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

>>Thus to convert a lowercase to an uppercase letter, subtract 32 from it.

Wrong -- that could be disasterous if done dimwittedly. The macro toupper() and tolower() should be used to convert a character from upper to lower, or vice versa because it is part of the C and C++ standards, and is portable across all compilers and operating systems.

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

Should be not very complicated. Just read the files in a loop

#include <string>
#include <fstream>
#include <sstream>

int main()
{
   std::ifstream in;
   for(int i = 1;  <= 100; i++)
   {
       std::stringstream s;
       s << i;
       std::string filename = "a.out";
       filename += s.str();
       in.open(filename.c_str());
       if( in.is_open() )
       {
          std::string line;
          while( std::getline(in,line) )
          {
             // do stuff here
          }
          in.close();
          in.clear(); // clear eof errors
       }
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to declare an object of type FLATMATE and then push it onto the vector

FLATMATE fl("John");
myvector.push_back(fl);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>According to my book/teacher (and in the past my compiler), a single-letter string can be represented by the ASCII dec number in single quotes

Either you mis-understood your teacher or your teacher needs to quit teaching and take up basket weaving. The decimal value of ascii codes are NOT put in quote

>>It actually gives me an error if I put what you suggested
Post what you tried because it seems to work for everyone else in this world (roughly 4 billion people) but not for you ;)

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

>>if (choice3=='89')

'89' is not 'Y'. There is no such thing as 89 within single quotes. Your compiler should have given you an error or warning on that, which I have to assume you ignored. if(choice3 == 'Y') is what you want. But what if you type 'y' instead of 'Y'?

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

If you wrote the program as MS-Windows GUI, such as it uses WinMain() instead of main(), then that link error tells me that you created the wrong kind of project. You should have started with a Win32 Project, not a Win32 Console Application (assuming your compiler is VC++ 2010).

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

Yup. That's all there is to it. Read the instructions carefully. I assume you will need two of those arrays.
>>Each vector will contain exactly 8 floating point values

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

A c++ vector is just the c++ implementation of a normal array. So when the instructions tell you there are exactly 8 floating point values in the vector, that means declare an array like this: float values[8]; If you are confused about how to use arrays then read one of these tutorials

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

>>Heres the build log...
For what?

Disable precompiled headers for that project. Or add #include "stdafx.h" at the top of each *.cpp file in the project.

And make sure its in a *.cpp file, not *.c. C programs can not use precompiled headers or STL containers such as vector

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

>>Its not copy-paste-able in VC++2010,

Funny -- I didn't have any trouble doing that. Just copy/paste into an existing console project.

vectors are c++ implementation of arays, not stacks. There is another class called stack. You might want to read up on STL containers.

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

Its all about something called the "comma operator" Here and Here are two more links

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

Those functions can be used in either console or GUI programs. There are a lot of win32 api functions that can be called from console programs.

FindFirstFile() and FindNextFile() are very similar in concept to opendir() and readdir() for *nix. All you have to do is include <windows.h> then use google to get the full descriptions of those functions from MSDN. I have even posted code examples using those functions.

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

If you are concerned about security in your programs then don't use pipes to execute M$ stock command. Most, if not all, those commands have win32 api equivalent functions. For dir you can call FindFirstFile() and FindNextFile() to do the same thing.

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

>>orly? 0.0

Huh??? The ls command you have in your link is probably from one of the gnu libraries, not standard MS-Windows command. You will not be able to run that program on other computers with MS-Windows unless you also install that ls.exe program.

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

you can not use sizeof to get the number of bytes allocated to an array. All sizeof(any pointer here) does is give you the size of a pointer -- on 32-bit compilers it will be 4.

There are two solutions I can think of:
1. Use vector instead of array, such as std::vector<double> ay; You can call vector's size() method to get the number of doubles it contains.

2. Pass the array size as another parameter to the functinon.

n0de commented: Thanks ;) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ls doesn't work on Windows 7

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Ancient Dragon>ls
'ls' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Ancient Dragon>

If you want the filenames then use /b option

C:\Users\Ancient Dragon>dir /b
Contacts
Desktop
Documents
Downloads
Favorites
Links
Music
Pictures
Saved Games
Searches
Videos
workspace

C:\Users\Ancient Dragon>

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

VC++ 2010 Express errors

1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::IFont>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VIFont@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IFont>::~Resource<class bge::IFont>(void)" (??1?$Resource@VIFont@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IFont>::Resource<class bge::IFont>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VIFont@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddFont(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddFont@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: void __thiscall bge::Resource<class bge::IImage>::SetFilename(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?SetFilename@?$Resource@VIImage@bge@@@bge@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::Resource<class bge::IImage>(void)" (??0?$Resource@VIImage@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::~Resource<class bge::IImage>(void)" (??1?$Resource@VIImage@bge@@@bge@@QAE@XZ) referenced in function "public: bool __thiscall bge::ResourceManager::AddImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?AddImage@ResourceManager@bge@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z)
1>ResourceManager.obj : error LNK2019: unresolved external symbol "public: __thiscall bge::Resource<class bge::IImage>::Resource<class bge::IImage>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$Resource@VIImage@bge@@@bge@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool …

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

>>but I can change it, it dosent matter too much to me.


Well it will matter to the operating system :)

>>How would I allow the function to return an array of chars? char* getStdOut(char *cmd) Now you will want to make that string getStdout(char* cmd) because a function can not return a character array that is declared on the stack as ps is declared in that function. You could change ps to a pointer and use malloc() to allocate memory for it, but using std::string in a c++ program would be a better and easier solution.

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

See your CONTROL PANEL link at the top of the page.

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

You are using VC++ 2010 on MS-Windows but attempting to run a *nix ls command???? On MS-Windows the equivalent of ls is dir.

>>strcat(ps,psBuffer);
You will have to initialize ps to 0 before that line. Do it when it is declared, char ps[1024] = {0}; I think it would be better to use a linked list because the results of dir can be very very huge. In c++ just use vector<string> filelist;

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

I don't know the answeres to those questions. I'd need the entire program so that I can compile/check it myself.

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

>>'Clean All Targets' (which I think is a complete rebuild?).

No it doesn't mean that. Clean means to just delete all the files that are generated by the compiler, such as *.obj, *.o, *.lib, *.dll, *.pch, etc.

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

After the validation you cn convert the string to an integer if you want to.

#include <sstring>
...
<snip>
int n;
stringstream s;
s << number;
s >> n;
cou << n << '\n';

Unless you are instructed to do so there is no reason to put each digit of the string in its own int variable. But you could do that too

int n[5];
for(int i = 0; i < number.length(); i++)
   n[i] = number[i] - '0'; // convert ascii digit to binary
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I mean something like this:

int main()
{
   std::string number;
   cout << "Enter 5 digits\n";
   cin >> number;
   for(int i = 0; i < number.length(); i++)
   {
     if( !isdigit(number[i]) )
     {
        cout << "You idot!  Numeric digits only!;
        break;
     }
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The easoest way to validate that all input only contains digits it to get the input as a string instead of an integer. Then you can easily determine if it contains any non-digit characters without screwing up the entire input stream.

>>while((!isdigit(numbers[k]))
Useless loop because numbers can not hold anything other than digits. And cin will not let you enter anything other than digits in numeric variables.

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

>>take same time as

Not necessarily, depending on how the compiler implements strchr() function. calling strlen() on every loop iteration is very very time consuming and I doubt any compiler will implement strchr() with that. On Intel compatible x86 processors compilers can use a processor instruction to do it.

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

Yes it is possible. A segment is determined by the address in ds register. It has nothing to do with align type. AFAIK segments are never closer than 16 bytes (one paragraph), which is the smallest amount of memory that will be returned by memory allocation function (int 21h, function 48h).

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

One way to do it is to use another character array to copy all the characters in s1 that are not in s2.

void trimString()
{
   char s1[] = "hello world";
   char s2[] = "el";
   char s3[255] = {0};
   size_t sz1 = strlen(s1);
   size_t j = 0;
   for(size_t i = 0; i < sz1; i++)
   {
       if( !strchr(s2,s1[i]) )
          s3[j++] = s1[i];
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>cannot covert from const char [2] to wchar_t
Hummm. If you are compiling the program for UNICODE then why aren't you getting similar errors on all the other lines in your program (such as line 5)?

You could have avoided that problem altogether had you used ifstream and getline() instead of C's FILE and associated C functions.

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

At the bottom of the thread you started you will see "Has this thread been answered?". The text under that contains a link to mark your thread solved.

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

He forgot to make array a pointer int* array = new int[size];

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

what compiler are you using?

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

I meant what programming language (c, c++, java, vb, shell, etc)

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

>>Can anyone help me how to do sample codes for these?

What language?

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

displayObject() returns void -- that can't be used with cout.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
const int SomeSize = 5;
const int SomeOtherSize = 5;
class ClassName
{
};

typedef ClassName SomeName[SomeSize][SomeOtherSize];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

During development I just copy the dll into the project's home directory (where the *.cpp and *.h files exist). That way you don't have to worry about changing the PATH environment variable.

When you compile a DLL project it will generate both the *.dll and *.lib files. The *.lib file is used in the application program that uses the dll just like it uses any other *.lib file from the standard C and C++ libraries. That means you have to add the name of the *.lib file in Project --> Configuration Properties --> Linker --> Input. On the right side of the screen add the *.lib to Additional Dependencies edit box. It should already contain several *.lib files.

After that you have to tell the IDE where to find that *.lib file. Add the path to Project --> Configuration Properties --> General. Then on the right side put the path to the .lib file in Additional Library Diectories edit box.

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

If you created the project as a DLL project then the configuration type will already be selected for you. You don't really have to do that step. At that point, just hit the Build Solution option

If you don't see a Build menu option -- located just to the right of Project menu -- then you need to change another setting. Select Tools --> Settings --> Expert Settings.

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

c++ Forms

private: System::Windows::Forms::TextBox^  myText;
<snip>
String^ str = myText->Text;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Now I'm gonna go get some sleep. Will get back to programming and thinking about your posts tomorrow.

Good. Better to start again with a fresh mind :)

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

>>1. malloc should have been done in the main() function, so that free is possible in the main() function.

That isn't necessary. There are several functions in the standard C libraries which allocate memory and are free'ed by the calling application program.

>>so this assingment has some frustrating boundaries
That's because you have failed to read and comprehend what others have told you about your program. Go back to the beginning and re-read our comments, then compare them with your program. You will then see your mistakes. For example I mentioned the problem with free() in your program over an hour ago, in my first post in this thread. Yet you have failed to change it. What's the point of us trying to help you if you just ignore us.

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

The two arrays in main() are declared wrong

int main () {

  const char array1[50] = {"asgfhararjsrj"};
  const char array2[50] = {"wajwarjwrjarjsdafj"};
  char *cjj;


cjj=combinearrays(array1, array2);
printf("%s\n", cjj);

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

line 15: >>cjj[100]=combinearrays(*array1, *array2);

cjj should be declared as a char*, not an array. And remve the start from that function call/

char* cjj;
cjj = combinearrays(array1, array2);

line 40: that loop will not work. You need to use both i and j counters.

for(j = 0; j< strlen(array2) j++, i++)
   text[i] = array2[j];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char combinearrays(const char *array1, const char *array2) {

The function needs to return a pointer to an array, not a single character.

>>return *text;
>>free (text);

line 45 -- free(text) -- is unreachable and will never get executed because of line 44.

line 44: should be return text; -- remove the star

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

Move line30 up to line 29 so that it's within the else statement.

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

the problem is that i haven't studied structures in assembly
i am supposed to deal with linked lists

Well you had better get to studying them because that's what linked lists use. In assembly language structures may be also called records.

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

Coding anything in c++ is going to be more complicated than in other languages. c or c++ is not necessarily the best language for doing some things.

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

You use normal win32 api functions to do that. Read this

Open the com port with CreateFile. Scroll down the page to "Communications Resources" for more information. And an example c++ program.