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

you can easily put the comma wherever you want it in the sprintf() format string. Just replace one of those pipe symbols | with a comma.

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

you should post variable declaractions too.

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

how about just posting the questions and we will post our responses?

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

temp variable is a character array. before adding the binary digit to temp the digits must be converted to one of the ascii characters '0' through '9'. for example: 1 + 48 = 49, and if you look at that ascii chart the number 49 is the letter '1'. Also note that the number 1 and the letter '1' are not the same thing.

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

0x30 is hexidecimal value of 48 decimal (use your scientific calculator to convert 30 hex to decimal). Adding 48 to a numeric digit will make it a printable digit -- see any ascii conversion chart.

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

>>Does my this solution use more than one variable ?
please read his second statement -- doesn't want to use memmove() or any other functions. I posted an (almost) complete example of how to do it without using any other functions or variables.

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

That's what's nice about stringstream -- make conversion very simple in either direction.

if you want to stick with char*, then use sprintf() to make the conversion. But if you do this you are not converting the C program to C++.

char *ConvertToString(float in_val)
{
   char *cp = new char[80];
   sprintf(cp,"%f",in_val);
   return cp;
 }

Here is the c++ equalivant

struct account {
     float amount;
     std::string value;
     int   day;
     int   month;
     struct account *InternalPtr; 
};

string ConvertToString(float in_val)
{
   string cp;
   strstream str;
   str << in_val;
   str >> cp;
   return cp;
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The examples in that previous thread use additional variables/functions to do the job. The OP wants to remove the character without using additional variables or functions.

I cannot take any local variables within the function.

I did got this solution of using recursion as well as using functions like strcpy() or memmove() but again, that implicitly uses more variables.

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

yes, it can be done with just the one pointer into the parameter, assuming the pointer is pointing to the character that needs to be removed.

Hint: you know that the string is null-terminated, so just copy *(ptr+1) to *ptr until *(ptr+1) == NULL. If it is not NULL then increment the pointer and do it again.

Give it a try and post code/questions if you can't get it. That's a pretty good assignment to teach pointers.

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

on MS-Windows os, use FindFirstFile() and FindNextFile() to iterate through all the files in a folder. *nix has opendir() and readdir(). boost libraries have os-independent c++ classes.
useing these functions you don't have to know anything about the file names or how many files there are. Just check the file's attributes (also returned by those functions) to insure the file name is not a folder/directory.

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

Wrong! All I need is the code and perhaps the text file he's using, then I can compile it from within my IDE. .

I agree you can do it, but when there are multiple files its just easier to post the .zip file. You can choose to download or not. A virus scanner will take care of any viruses that the zip file may contain. And it saves a lot of time copy the code from the browser and pasting it into my own project.

[edit]the files speterson posted have the same problem(s) as the zip file you dislike so much.[/edit]

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

>> srand((unsigned) time(&t));
you don't need the argument to time()

srand((unsigned) time(NULL));

>>#if defined(_MSC_VER)
delete the above line and the corresponding #endif. time functions and rand functions are both standard c/c++ library functions that are supported by most c or c++ compilers.

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

here is how to enter the characters of a number as a string and convert to float. If this code is too much for you then you should probably shelve your project for awhile and concentrate on learning c++.

#include <string>
#include <strstream>
#include <iostream>
using namespace std;

int main()
{
    string input;
    float num;
    strstream str;

    cout << "Enter a number...";
    cin >> input;
    str << input;
    str >> num;
    cout << "num = " << num << "\n";

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

Can you post just the code here. I don't like downloading zip files in case they contains viruses and other known nasties.:cheesy:

in this case, no. a zip file is better because it contains lots of files and some of them contain binary information. Besides, you should always be running a virus scanner which will catch viruses.

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

No one has even said ANYTHING about disabling the start menu...In the mean time I have found out how to not allow a user to click it, but they can still use the windows key (on the keyboard to access it...I have already been accused of trying to make viruses on other sites, but I am actually trying to lock my computer from unwanted access (little brothers, sisters) So if anyone could tell me how to do it that would be wonderful.

The first place to begin your research is at Microsoft. There appears to be several threads about that.

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

that error means you have not coded the function. compare your program with the template your teacher gave you and you will see your code is missing that function.

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

1. you need a semicolon after the declaraction of salary

2. count the number of closing braces in that function. You have one too many.

>>I think that's my stress level going up
Yup, that happens to all of us. When you get stressed out just get up and go have a cup of coffee or something. DO NOT drink alcohol -- it does more harm than good.

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

>>// main will not require any modification

you did not follow instructions. put main() back the way it was and add your code in the wages() function.

>> for( int i = 0; i < 3; ++i )
There is no limit to the number of salaries you can enter. So you are using the wrong kind of loop. I suggest using a do-while loop, something like this:

do
{
        cout << "Enter employee gross sales ( -1 to end )" << endl;
        cin >> sales;
} while(sales >= 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do the assignment one step at a time and it will be a lot easier. If you try to do it all at once you might wind up just getting more confused.

Start with function wages(). You know that you have to have a prompt "Enter employee gross sales ( -1 to end )" inside that while loop, and somehow you have to allow the user to type in a number into the double variable sales, which is already defined in the function. Once you get that you need to calculate the commission with is 9% of the sales. That's simple 2nd or 3d grade math -- employee commission is $200.00 plus (sales * commissionRate).

Get that all working then come back for more questions/answers.

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

I am sorry for my mistake...I had no idea I HAD to encase the code in tags...I thought it was optional.

It is optional, DaniWeb does not enforce that rule, but moderators do. -- If you don't follow the rules then you will greatly decrease the probability that anyone will take you very seriously and answer the question. Many people see unformatted code and just ignore the whole thread.

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

>>if (Compare1 == Compare2)

you can not compare C character arrays like that. All that is doing is comparing two addresses, not the strings. use strcmp() for that

if( strcmp(Compare1, Compar2) == 0)
{
   // the two strings are the same
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know how its done, but here is an example

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

Before you jump into windows programming with both feet, you should read this intoductory tutorial.

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

Mr SOS -- it works up to a point -- gives the famous message box that a fatal error has occured -- similar to core dump in *nix.

Jo: There is a very simple fix to the problem -- check for an empty string

int main()
{	
	std::string myArray[] = { "January", "February", "March", "April", "May", "June", "July",
		"August", "September", "October", "November", "December", ""};

	for(const std::string* str = myArray ; *str != ""; str++ )
                     std::cout << *str << '\n';
                std::cout << '\n';
				
	std::cin.get();

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

>>for(const std::string* str = myArray ; str != 0; str++ )

Now how can that ever work because myArray is not a nulll-terminated array. You are attempting to apply C-style character array techniques to a c++ string, and won't work.

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

but I thought that there was also a way that you could use the beginning and end of the array to loop threw the array like this .

use vector<string> and you can do what you want using iterators.

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

>>void printarray(int *,int);
That is the wrong prototype because one star is a 1d array.

void printarray(int **,int);

or
void printarray(int *array[],int);

or
void printarray(int array[MAX][MAX],int);

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

If you google for ODBC you will find a lot of information. and this tutorial

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

you will need to learn SQL query language and, possibly ODBC functions. google for those keywords and you will get pleanty of help and some free c++ classes. This is no small feat -- there are entire books written on those two subjects. Definitely not for begining c and c++ students, you will need at least a fundamental understanding of those languages.

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

Besides this, I am quite happy with our system. I just see the need for vast improvements. There are scores (see, 100's of 1000's, if not more) of American people who go daily without their prescribed medicine, (the very medicine that just might cure their ills) because they cannot afford to pay for it and they do not have insurance. Medicine has become the new Mercedes, Nike, Apple-- designer quality at designer prices. Capitalism run amock. How inspiring. :rolleyes:

I agree -- there is no such thing as a perfect system. I mostly disagree with the term "pathetic Health system of the U.S. " -- it is better than most.

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

There are many breakthroughs that occur. I do not disagree with this. Lives are saved. But in the majority of cases, the symptoms are treated, not the root of the disease. This is Western medicine; Large companies do not make large profits from cures but from prolonged use of their products that simulate an awkward "improvement", that is, some symptoms digress while new conflicts grow from:

  1. Side Effects from new treatement\ medicine
  2. The weakening of the human system from the chemicals, err, "medicines" :twisted: prescribed, hence, making the person(s) more sick in the long run

I am a huge supporter of science and research, but I will not sit here and say I am absolutely mad for the pathetic Health system of the U.S.

And sometimes, the grass is actually greener. Perhaps? :surprised

If you think you can do any better than those scientists -- be my guest! They will be more than happy to allow you to work along side them if you are qualified.

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

>>but what is a container?

an array, std::vector, std::list, etc.

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

Please use code tags when posting code. Read the information in the links below.

This is how I code it in c/c++:

for(a = 0; a < highSubscript-1; ++a)
{
    for(b = 0; b < highSubscript; ++b)
    {
            if(array[a] > array[b])
            {
                temp = array[a];
                array[a] = array[b];
                array[b] = temp;
             }
      }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think this is a case of "gass is always greener on the other side of the fence".

>>do the Billions spent on medical research actually cure anything significant
Of couse it does. One example: I went through angioplaty (heart) surgery a year ago. This was first approved for use in USA in 1994. And there have been some improvements since then. Hospital stay is only overnight. There are medical breakthroughs all the time -- just because Christopher Reeve and Michael J. Fox have not been cured does not mean a cure will never come.

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

did you even read the story? He is far from destitute, and IS indeed getting medical care.

But now, weak from chemotherapy and armed with a desire to pass on his belief in random kindness, Secret Santa has decided it's time to reveal his identity.

He is Larry Stewart, a 58-year-old businessman from the Kansas City suburb of Lee's Summit, Mo., who made his millions in cable television and long-distance telephone service.

If health care in USA is so bad why do people come here both legally and illegally from all over the world to get it? I have read a few of the horror stories from other socialized countries such as UK, canada and France. There is a two year waiting list to see a doctor -- where I live I can get an appointment within 24 hours if I need to.

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

>> scanf("%d", &av[y]);

you have to pass a pointer to scanf() as shown above

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

>> scanf("%d", av[x]);

replace variable x with y.

there is no need to pass variables y or z to function avg. Just make them local variable in that function.

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

Pointer of type void can point to any type of data if thats what you asking while int type pointers point only to int data and char type pointers point to char type data.

That is not true. You can make char* point to int* and vice versa. That happens frequently, especially in database and socket programming.

Here is an example:

int x = 123;
char buf[5];
memcpy(buf,&x,sizeof(int));
// now buf contains the binary representation of the integer
//
// convert back to int
int y = *(int*)buf;

>>But, so how can I find out what my restrictions are to pointer types char*, int*, and void* ?
There are none that applies to one type of pointer an not to the other types. typecasting may be necessary to convert one type of pointer to another, as shown in the above example.

Alignment does NOT change the size of a structure, only the address where the object is located. Packing will change the size of the structure by either adding or removing holes. If you want to remove all holes from the structure pack the structure on 1 byte alignment as in the example below. Change the value of the pack and you will get different structure size.

#pragma pack(1)
struct address
{
	char *name;
	char *street;
	char *town;
	long int number;
	long zip;
	char state[2];
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Microsoft compilers has an alignment option to align data on 1, 2, 4, 8, or 16 byte boundries. I think Dev-C++ and other compilers do that too. This is to help improve memory access time.

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

why?

There is always more than one way to do something and often one way is just as good as any other. Some things are just a matter of programmer preference. Some programmers don't like declaring "using namespace std" becuse they claim it brings everything in std namespace into scope. Myself, I say "so what? -- the compiler can handle that very well, thank you". But there is nothing at all wrong with not doing that either.

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

>> i think the the Include should be:
>> #include <string.h>

string.h is used in C programs. C++ should use cstring as the OP posted. He did it correctly.

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

maybe using an uninitialized pointer ? Can't say for sure until you post some code.

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

do it just like you would from the command line.

system("dir > myfile.txt");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, tried this

int longest(void)

{
	char line[BUFSIZE] = {'\0'} ;
	int counter=0;
	int longest=0;
	char fname[128];
	FILE *file;
	
	file=fopen(fname,"r");
	
	

    while (fgets( line, BUFSIZE, file )!=0)
	{
	 
	 counter=strlen(line);
	

	 if(counter>longest)

		{
		 longest=counter;
		}
   
	}
	return longest; 

}

I'm getting a Debug assertion failed with fgets.c.Seriously, wouldn't it be easier to use something other fgets()? (Just asking don't crucify me)

The debug assertion error fails because the file pointer is NULL, not because fgets() does not work. fname[] is an unitiailzied string which will cause fopen() to return NULL instead of a valid pointer to the FILE object. Your program should check for a vaid fopen() return value.

file=fopen(fname,"r");
                if( file == NULL)
                {
                   // display an error and terminate the program
                 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> while ((c = fprintf(file,"%c",&c)) != EOF)

Please, stop coding if you know nothing about what you are doing. At least look up the functions before you indiscriminately toss at your program like darts at a dartboard.

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

>>Excuse my crappy English, I'm Dutch
Your english is a lot better than my dutch:eek:

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

until counter = all chars in file?

on MS-Windows os it will not be the same as the file size because it does not include one of the two line terminating character(s). To get the file size add one to counter for each line read except the last line. The last line may or may not contain '\n', so the program has to check the last character to see if it should also account for the '\r' character.

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

Please note that " 0 " is not the same as " NULL "

Regards Niek

On recent compiler, yes it is. NULL is just a define which is defined as 0

#define NULL 0

on many very old compilers NULL may also be defined as (char*)0.

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

>>Yeah I'm using c style strings in c++ code get over it
that is ok if you have not yet learned about std::string or your instructor requires character arrays.

The function causes buss error probably because it does not return the stream. Your compiler should have given you either an error or a warning about that. Do not overlook warnings because they are often errors.

>>char mystring[16];
too small. you forgot to make room for the null terminator

>>Normally I wouldn't bother about something that could be fixed by coding seperate lines instead of putting it all in one
That would fix nothing because the compiler could care less.

What happens if you type in an ip with incorrect format? strtok() will return NULL at some point and the operator>> method will crash.