WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Actually, you read from one file, then write to another file. You don't want to read and write to the same file. It gets too complicated.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Properly formatted:

if (((strcmp(ptr,"int")) || (strcmp(ptr,"float")))  ==  0)

No it is not. That does not work. Example:

#include <string.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	char *ptr = "float";

	if (((strcmp(ptr,"int")) || (strcmp(ptr,"float")))  ==  0)
		printf("Yes\n");
	else
		printf("no\n");
	return 0;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

thnx a lot for all urguys help i really appreciate it!

Yeah, where were you guys when I was learning to code? I could have partied more and let you do my home work for me, too! :rolleyes:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Waltp has interpreted my point correctly.
A test script using C to run a pre-compiled program with the input data in a separate file.

We treat a program as a black box w/o having any ability to modify the source. This is a software that a vendor delivered to us. With the set of requirements, wWe will now have to creat a scenarios (input data) to test this piece of new release software.

As a newbie, I just want to understand that simple concept, then apply toward that large scale testing.

But not one question answered. We therefore can't help because we don't know what to do either. Sorry.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ok. So it looks like I was approaching the problem incorrectly. If I create the 2-dimensional array, I think I can remove entire columns using a loop with ArrayList->RemoveAt. For example, to remove column 5: theArray->RemoveAt[5] and iterate through the end of the rows. I'll give it a shot. Thanks.

Not what I said. Please read again carefully to see the easy solution. You don't start with 50 columns. You start with the total you need at the end of processing (like 10).

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In other words:
You have 3 files
1) Data File -- what reads the data file?
2) Program -- calculates data from the file. How does the data get into the program?
3) Script file -- somehow runs the program and associates the data with the program. This depends on how the other two files interface.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Update the field's old value with a new value.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you keep explaining you are new (thinking we'll forget I guess), I'll assume you know practically nothing about C++ but know just enough to understand arrays and the string type.

  • Define a two dimensional array of strings with as many rows and colums as you need
  • Open the data file
  • Start a loop to read each line into another string
    • read a line
    • look for a comma
    • move the previous substring into your string array into col 1
    • look for the next comma
    • move the previous substring into your string array into col 2
    • keep going until you have all the columns saved
    • loop back
  • Close the file
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello...I need to write a program where i need to copy each word of a string into an array...
Eg(string s="hello how are you" arr[0]=hello,arr[1]=how....).
any help:?: ??

Thanks mate...but i need the solution in c++...is it posible??...sory for not specifying this at the start

In other words, "Thanks, but I can't turn that in as homework. Please write my homework for me properly."
:confused:

Grunt commented: Exactly :) [Grunt] +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I've placed a CSV file into an array with C++ with each row being a single array element, but the file contains many, many columns that I don't need. I only need columns 1,2,3,4,6,7 out of about 50. Is is best to read the full value into the array and then edit it or only read in those values that I need?

This depends on what you are going to do with the data read. If you are going to edit the data in those columns and write it back to a file, along with the rest of the columns, you will have to read and store all the data. If you only want the values, and they are discarded after use, you can create an array of only 6 elements with multiple rows, and store the columns you need to that array.

Remember I'm new at this, so I'm sure my code is horrible. This is in Visual Studio 2005. The Console::WriteLine and the cout of the lineCount are only for my purposes to make sure the program was actually working. They will be removed later.

This response doesn't seem to answer any of WolfPack's questions. We still don't know enough to answer your question. And yes, your format is horrible. After every { indent 4 spaces. Before every } unindent. Then you program can be followed.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

PS: Don't post the same question twice ;)

And please start using code tags, and posting with titles that have some meaning -- like a short description of what the program is about.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

straight() is a terrible function. What about something like

isStraight=true;
for (i=0; i<8; i++)
{
    for (j=0; j<5; j++)
    {
        if (hand[j+1] != hand[j])
        {
            isStraight = false;
            break;
        }
        if (isStraight == false)
        {
            break;
        }
     }
}

Of course modified for your design...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why use dynamic allocattion to define an 8x8 array? Just define board as int board[8][8] .

Create a function to display the board and just call it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How would i specify a Win32 project in Dev-C++? All that's listed is console, windows app, static library (.a), DLL and empty project.

Win32 == windows app

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What's tha maximum value a signed char can handle?

Niklas commented: Thanks for your help. Didn't catch that. +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, this question belongs in Software development -- IF you are trying to develop the code yourself. If not, just use a calculator.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I want to use frame because with static page whenever I add a new comic page then I need to add a new page and do a small editing to the rest of the other page. So when I reach 6th page I do 5 page small editing.

I assume the small editing is linking the last page to the new page. Instead, just have the link go the the next page and have a "next installment coming soon" page that you just rename to page 7 when you load page 6.

Using frames, you still have the same amount of editing. It's just in different files.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Arrays must have a name.

Not in a prototype. Onlyt the type of the parameter is needed.

Curtis:
The file must be opened in the execution portion of the code since opening a file is an action. You have it in the declaration portion of the code. Put it in main() Use code tags. It's much faster and easier than coloring your code by hand and preserves the structure -- assuming you have structure. ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

File : Make project.EXE

And please don't hijack threads. You can make your own.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Good one, i completely agree with you on English and computer lang depending on the kind of area i am in but just wanted to know whether Microsoft still holds a market there or the opensource revolution has started to pick up there. Here in India its all PHP, C and MS technologies. Wanted to know the senario there. I was plannign to do my MS in US and wanted to know what kind of language should i stress on here in India so that i can just start developing softwares out there along with some big shot company.

Thanks in advance.

I don't think it's that much different here. C/C++, PHP, and unfortunately MS (is my bias peeking through?) are strong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hey i was just wondering which is the prominent langauge in the United States of America which is used for development. I know it sounds a bit amatuerish but i dont know how to frame this question. Just wanted to know which langauge is worth learning so that the one who knows it would not go jobless in America. Which languages are taught in Universities like Southern California University and are included in the course curriculum.

Waiting eagerly for your reply.

I'd say English.

Computer language depends on what kind of development. You'll find different languages for different arenas. IMO, C++ is still the catch-all language, though.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As far as part c is concerned i will give you small snippet and you can do the rest of the parts yourself.

#include <iostream>
using namespace std ;

int main (void)
{  
   int g [5], counter;
   for (counter = 0; counter < 5; ++counter)
      g[counter] = 8 ;

   cin.get () ;
   return 0 ;
}

HOpe it helped, bye.

I don't read c that way.

c) Initialize each of the 5 elements of single-subscripted integer array g to 8.

To me that's a single statement. Define c and load values during the definition -- similar to the way array was handled.

I love instructions that are vague and interpretable... :confused:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not to bump an old thread,

Then why did you?

After three years do you really think he's been waiting for an answer?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

money --> dearth

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

how to check the folder is exist or not?

Try creating the folder.
a) If you get an error, it exists or can't be created.
b) If not, it didn't exist but does now.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is it better now. sorry I did it in a hurry.

#include <iostream>
using namespace std;
int main()
{
     int number=10;
     int x;
     int your_number;;
     char answer = 'y';
     cout<< "\n\nguess the number:\n";
     cin >> your_number;
 
     while (your_number != number || answer == 'y')
     {
       if(number == your_number)
       {
             cout<<"Congrat!\n\n";
             cout<<"\n Want to try again? ";
             cin>>answer;
             if(answer == 'y')
                 your_number = 0;
             else
             break;
       }
       else
       {
             cout<< "\n Guess number:\n";
             cin >> your_number;
       }
    }
 
return 0;
 
}
 
this is not part of your code.  ending code tag should go here 
SAMPLE OUTPUT:
NOTE:It was run on a linux machine.
 
smg@samoguz-desktop ~/Desktop
$ ./num
 
guess the number:
2
Guess number:
3
Guess number:
10
Congrat!
 
Want to try again? y
Guess number:
6
Guess number:
7
Guess number:
10
Congrat!
 
Want to try again? n
smg@samoguz-desktop ~/Desktop

#1) Does while (your_number != number || answer == 'y') do what you want? Make a truth table.

#2) If your while loop is already testing if the number is == or != just let the loop end. Then verify outside the loop it's because of the == and output the results. That will make your while loop simple and easier to debug. Just put in it the stuff that has to go in it. IOW separate the 'work' with the 'result display'

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please don't be so cute with your questions. Ask it directly so we don't have to figure out what you want to know. The code is supposed to show us what you've tried, not be the question.

#include <stdio.h>
#include <string.h>
char* string(char *str);
int main()
{
printf("%s\n ",string(" in this method "));
getchar();
return 0;
}

char *string(char *str4)
{
char str[25] = "How";
char str2[25] = " do I ";
char str3[25] = " return a string";
strcat(str,str2); //append str2 to str and return str

//strcat(str,str3); //append str3 to str and return str
//strcat(str,str4); This line cause the program to close at runtime with an error


return strcat(str,str3);
}

Basically, you can't do it this way.
1) when you return, the string str is deleted, therefore there's no data left.
2) strcat() returns a pointer, not the string. The pointer returns but the string has been deleted. See 1.

The way to return the string is define the string in the calling routine and pass the string into the function.

As for the crash, how many total characters did you load into str[25]?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try rebuilding the other apps. If they don't work it sounds like your libNcdd.so got corrupted and you need to replace it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since mkdir() is not a standard C/C++ function, it's not surprising it doesn't work. The standard language is designed to be ignorant of the 'outside world' (directories, screen, keyboard) so anything that uses them outside the rudimentary I/O is compiler dependant. You'll have to look through your compiler documentation to see what functions it provides.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I haven't done this since I left DOS, but I believe you have to load the driver in the System information from the Control Panel. I don't believe config.sys is read in today's systems.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is the top decimal value that kbhit() catches when you hit a key? I didn't know about kbhit. So I coded the entire thing from scratch. It works. But the UP arrow key for example is " H", that is: NULL, capital h. It is actually 2 characters. Does kbhit() catch 2 characters? And could you provide a sample program that prints on the screen that an arrow key was hit, like I coded my sample program? I am curious about this apparent quick way that you provided.

kbhit() doesn't catch characters. It returns TRUE if a key has been pressed, FALSE if no key is waiting. That way your program can do whatever processing it needs and not wait for a key. In effect it makes the keyboard interrupt driven. Leave out the kbhit() call if you don't need to test for keyboard readyness.

As for a sample program, just output the value of the int egers ch1 and ch2.

Salem commented: rep++ Salem +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I usually do it with this:

if (kbhit())
{
    ch1 = getch();
    if (ch1 != '\0')
    {
            // process a normal keystroke
    }
    else
    {
        ch2 = getch();    // get the arrow or function key
        switch(ch2)
        {
                // process the arrow or function key
        }
    }
}

You can use this to discover what the key values are.

This only works for compilers that have getch() and kbhit() defined, of course.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree, you probably won't even need to learn c++, java and the .net is the languages that businesses focus on nowadays.

Doesn't sound like you've been in the industry very long (if at all) if you think Java and .NET is the current focus. Sorry, it's C/C++. Web design is still a small part of the coding base. There is no way you can write system contols in Java, and microprocessing and .net will never be compatable.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My bad. Let me know if you can read it now.

OK, now indent your code so it can be read. After every { indent 3-4 spaces, before every } unindent. Can't tell which open brace goes with which close brace with unformatted code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Well, contrary to what you guys have heard, C/C++ is probably the most used language in the industry today. C# is a nitch language, Java is limited, too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you want this program to work on Macs and Linux? If so, stay away from anything .NET or Windows specific.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What was wrong with your first technique? It looked fine to me.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Well I coded for the backspace. Here is the code if anybody is interested...

if (str[num] == '\b')
      {

        str[num] = '\0';
        printf(" \b");
        str[num-1] = '\0';
        num = num - 1;
      }

I put it in a Do-While loop

A slightly better way may be:

if (str[num] == '\b')
{
    printf(" \b");
    str[--num] = '\0';    // sub 1 from num and set to \0
}

No need to zero the \b. Just zero the previous character.
Also, what happens if there are no characters and num is 0?

str[num] = str[num] - 'A' + 'a';  // converts it to lowercase

To convert to lower case, look up the tolower() function.

And as Ancient Dragon mentioned, what happens when num is 20 or greater?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Its normally a rule of the thumb to close the file pointer as soon as you are finished with it to avoid the undefined behaviour of the file stream which you have opened.
----
It is not called not writing into the files, as mentioned by me earlier, it is called undefined behaviour when the file stream is kept open.

Undefined behaviour can imply successful write as well as an unsuccessful write, but cant be determined when that happens. Use the funtion int ferror (FILE* file_ptr) to check whether the file stream is corrupted or not.

I'm not sure what you are saying here. It looks like you are saying if a file is not closed you enter the realm of undefined behavior. This is the first I've heard this. Can you point out something that substantiates this view?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ok,

I'm using the Dev-C++ 4 compiler along with gcc.

I would have preferred it to be standard C, but since you informed me that it cannot be done with standard C, then I might have to suffer a non-standardized design, which isn't a big deal, I just kind of wanted to take it to any platform I wanted. Right now though, I'm just programming for Windows.

In that case, getch() is your function. Also look into kbhit() , if Dev-C has it. It's extremely useful with getch() .

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You can't in Standard C. Some compilers have special functions that are not portable that can accomplisht what you want, but it's generally different for each compiler. So, if you want to enter the realm of non-standardization, we need more info.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't think I understand the problem.

I am a newbie to C++ and I'm not sure of anything at this point in time however,I got a problem with the starting phase of this program that well prompt the user to input a single character and output a inter4national Civil Aviation Word !!!!!

So you prompt the user to enter a character.

The prolem that I have is that you have to enter a character before it will start...

Ummm, isn't this the definition of "prompt the user to input a single character"? Why would this be a problem?

... and it closes after just one entry

Bottom of the program:

case 'Z': cout << "Zulu";
            break;
  default : cout << "Error";
}

cin >> a;

    return 0;
}

Output the information, accept a character (which reads the [enter] from above -- remember, you entered a letter AND the ENTER key) and exit. The only problem I see is the program probably doesn't wait at the end. Change the top cin to getline to keep the input stream clean, read it into a string and move the first character of the string to letter and continue.

Also, #include "stdafx.h" i not necessary.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Need details...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes i completely agree with Mr. WaltP

Mr.? Makes me feel old.... :)

For small exercies it doesnt make a difference...

I really wish people would stop saying crap like this. It does make a difference whether large or small. It's just wrong. Period.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But standard doesn't stops anyone.

Standard also has gets() and goto , too. And when you're driving, the brake doesn't have to be used at a red light.

Bad practices are bad practices, even when they are allowed. The C standard also allows this program to compile and run:

#include <stdio.h>
int GetDenom(int val,int *den){int i;int dp=0;for(i=1;i<=(val/2);i++){if((val%i)==0){den[dp++]=i;}}den[dp++]=val;return(dp);}
int main(){int i, v;int val,den[100],denp;v=0;for(val=2;val<10000;val++){denp=GetDenom(val,den);if(v<denp)v=denp;printf("%4d",val);printf("(%3d):",denp);for(i=0;i<denp;i++)printf("%3d",den[i]);printf("\n");}printf("v=%d\n",v);return 0;}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In case you ever intend to compile that program as C++, you can't call main() in a C++ program.

And you should never call main() in C either.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Get the return value from the msgbox call. It returns the button value pressed.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I was wondering what an appropriate programming language would be for creating a simple yet expandable (GUI) operating system. Is it possible in:

Python?
Java?
Perl?
QBASIC?
Ruby?


Thanks!

No.

C, C++, Assembler, maybe ForTran or Pascal, but doubtful. Dec-10's Tops-10 I believe was written in Bliss.