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

you should read the Read Me threads at the top of this board. They contain all (or probably most) of the information you are looking for.

If you want to print simple text files you can treat the printer as any other ordinary text file. The file name of the printer will probably be "LPT1:", prividing the printer is connected directly to your computer.

Writing to a file is almost identical to writing to the screen. Only addition is that in C you will need a FILE pointer. Search these threads for FILE and you will find hundreds of examples. For c++ use fstream class.

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

If you know how to use pointers then you can do this:

// declare initial 2d array;
char **array = 0;
// number of strings it will hold
int   arraySize = 0;

// allocate a block of 10 pointers which will store 10 strings
arraySize = 10;
array = realloc(array, arraySize * sizeof(char *));

// store a string in the 0th array element
array[0] = strdup("Hello World");

You will put the last few lines inside the loop that reads the file. Use another integer to count the number of lines that have been read. When that counter is the same as arraySize in my example above then you will have to expand the array to accommodate more strings. Do that by increasing the value of arraySize by some value, say 10.

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

1. is that 4 and 2 and 5 and 6, or 42 and 56?

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

If you can't use build-in standard C functions, then you need to figure out what I posted.

Any decimal digit in a string can be converted to its binary equlivalent by simply subtracting the ascii value of '0'. For example, '1' - '0' = 1. If you look up the values of '1' and '0' in a standard ascii chart you will find that a '1' has a decimal value of 49, and a '0' has a decimal value of 48. So 49 - 48 = 1.

After converting the digit to binary as previously explained you have to add it to the previous value of the final result. First shift all the digits previously converted to the left by 1 place, which is done by simply multiplying the value by 10, when add the value of the new decimal digit.

Now loop through all the digits in the string you posted and do the math as I illustrated previously for each digit. Give it a try and post your code (in code tags), and ask lots of questions if you need to.

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

you could convert one character at a time. start out by multiplying the result by 10 add the character and subtract '0', similar to how you would convert an integer

char inputstr[] = "123.45";
float result = 0.0F;

// convert 1st character
result = (result * 10) + inputstr[i] - '0';

That will work for all the characters that preceed the decimal point. After that you need another float, do similar math as above (but you don't need to multiply by 10), divide the result by (10 * number of decimal digits) and finally add that to the result. Example:

char inputstr[] = "123.45";
float result = 0.0F;
float temp;
int nDecimalDigits;'
// convert 1st character
nDecimalDigits = 1; // initialize this outside the loop



temp = inputstr[i] - '0';
nDecimalDigits *= 10;
temp /= nDecimalDigits;
result += temp;

What's not shown above is that you have to put that code in a for-next loop with i as the loop counter.

Confused now?

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

>>Is this possible? If it is, How?
yes, use the -o option and specify the full path to the name of the object file. BTW: *nix doesn't use MS-Windows .EXE naming convention -- executables can, but normally do not have an extension.

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

>>The code I have written so far works, but it prints the entire code

If it prints the entire code then it doesn't work, does it.;)

line 8: this is a c++ program, so replace the char array with std::string, which will allow you to enter a file name of any length up to the limit set by the operating system.

Line 16: if the file name contains spaces then that line will not work. Safer if you use getline().

lines 30-37: not a good way to detect eof. Don't read the file one character at a time -- that's too much work. Here's a simpler way to do this

std::string line;
while( getline(InStream,line) )
{
      std::string::size_type pos = line.find("//");
      if(pos != std::string::npos)
      {
           std::string word = line.substr(pos);
           cout << word;
     }
}

This doesn't solve the /**/ type comments but should work the // style commens. This was not compiled or tested, so use the above at your own risk.

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

I eat MD about once every three months or so. The trick to not getting fat while eating there is to drink a diet soda with the mean. Diet soda soaks up all the fat and calaries from the hamburgers.

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

It's taken 30+ years for insurance companies to bring tobacco companies down to where they are, and they have a long ways to go.

not even close to 30 years! try 12 years :)

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

bush = red, blair = blue?

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

Better link:

http://www.speakout.com/VoteMatch/senate2006.asp?quiz=2008

yea, but it doesn't show the comments from stltoday.com stl louis newspaper current affairs forum.

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

lol im just reading a book about virginia actually. Thats a wierd coincidence.

Scottish elections soon (less than a week).

Watch what you say about Virginia -- that's my sister.:D :D

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

Take a short presidential test to see how you stack up agains presidential candidates.

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

So what does an orange rep mean then? I have quite a few, will i be banned?

:D No. Only infractions can do that (unless, of course, Ms. Dani does it herself). We all can do that for you if you wish ;)

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

actually there is -- go to your control panel where it shows the rep points you have received. bad rep is also shown there.

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

I'm like 'Stein.. A fiscal conservative, but a social liberal... I tend to vote republican most of the time, though.. (Which has only been like once since I just turned 18 this year lol)

:) :) I guess that means you have never voted.:-/

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

I'm a registered republican but have been a switch-voter in past decades -- meaning voted both democrate and republican depending on who was running. I even voted for Ross Pariot the first year he ran. If Obama gets the democratic nomination then I'll probably vote for him. If not then I may vote republican again, depending on who all is running.

I would never ever vote for the Libertarian party even if God himself was running on that ticket :) They are just tooooo crazy, although I have liked a few of their ideas.

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

I don't see the line that is displaying the average, but I suspect the problem may be here:

>>average=grand_total/x;
since grand_total and x are both integers the vaue of average will also be an integer. typecase the two integers to float and the compiler will use floating point math, not integer math.

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

I sort of agree with Salem, I always have to study and think more about code whenever I see if( N < i) because to me its not the natural way to thin -- I normally think is i greater than 0?, not is 0 less than i. I understand the reason for coding backwards like that, and would probably eventually get used to it. There are not many compilers that have options to detect the reverse. VC++ 2005 Express doesn't even produce a warning on its hightest level for this code

int i = 10;
    if(i = 5)
    {
        i = 0;
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post your code. It doesn't matter whether it is a float or double -- the problem is not the data type but how you are trying to display it. If this is a C program and you are using printf(), then the format string needs to be "%.1f", not "%d".

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

I actually took the time to do that project and find some confusing instructions:

>> Add class level attributes and methods to maintain the list of loans.
This is an inventory program, not a loan progam.

many of those new Inventory class methods need to be static, not class-level member functions. For example, searchInventory can't be used as a class-level function because you need an instance of the class to call it, which doesn't make sence. Several others are like that too.

I think you need to get clarification of these issues with your instructor.

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

The descriptions appear to be pretty clear to me. Just start at the top of the list and implement each one at a time. After you do the first requirement then compile and fix all errors. Then go on to the next requirement.

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

This thread may interest you. But no, you can not use those libraries with any Microsoft compiler.

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

yes rectangles are pretty simple, arcs and circles are much more difficult and don't look good because of squared-off corners.

you can check out graphics.h that is supported by Boaland's compilers. But that compiler may not support most current c++ standards that you may be studying.

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

depends on the operating system if you want GUI shapes what look like the shape should. But if you are a beginner that is way to far advanced for you. But if you're looking for punishment, you can use Windows GDI functions

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

Option 2 is slower because there is a lot more code to be executed.

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

that's a pretty good start. have you learned linked lists yet? if you have, then use a linked list to store the strings. If not, then just use a simple array of pointers as in your previous post. Just make an array large enough, or you can use malloc() and realloc() to dynamically increate the array size as needed while reading the file.

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

benefits: none

implications: post stuff that is helpful to others. The more people like what you post, the more of those little green squares you get. The opposite is true also, you can get bad rep too.

jbennet commented: heva some rep from jbennet +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

// strop off the '\n'
if( teamid[strlen(temid)-1] == '\n')
teamid[strlen(temid)-1] = 0;

just a bit confused on how to add this to the code, ive managed to add the first bit but with the "teamid" and "temid" its saying that the statement is not declared.

thanks for your help again im very thankful

you need to recognize and correct the mispellings in my post when you type (or copy/paste) it into your program. When your compiler gives you an error message you have to look at the line, find the problem, then correct and recompile.

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

You could create a structure to hold the data for one candidate, and create an array or linked list of that structure for each candidate in the input file. After the file is read, sort the array in ascending order. Finally print the array as desired.

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

use FILE and associated functions in stdio.h. First call fopen() to open the file, then in a loop call fgets() to read each line. After end-of-file is reaches call fclose() to close the file.

If you use an array of char pointers as you posted you will want to call malloc() to allocate memory for the pointer before copying the line into the array.

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

use ShellExecute() see here and here

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

I would expect memory allocation functions would use a couple of linked lists -- free memory list and used memory list. When a function calls new or malloc the free list is searched for the smallest block of memory available to satisfy the request. when found it will add the block to the used memory list. Then when delete or free() is called the block is put back into the free list. After some time the free list gets pretty fragmented.

The problem you face is how to scan the free list and combine nodes with adjacent blocks of memory. The structure of the node probably contains a pointer to the beginning of the block of memory and an unsigned int that is the amount of memory, something like this:

struct node
{
    void* block;
    unsigned int size;
    struct node* next;
};

With that you can use normal linked-list techniquest to iterate through the linked list and compare pointers ( thisNode->block + thisNode->size) is about the value of next->block.

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

>>this codes have alot of erro
Well, you need to fix them :-/ Look at the first error, fix it, then recompile. If more errors then repeat the above.

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

first, use std::string's find() method to find the first space, then use its substr() method to extract the first word

std::string line = "name    =  John";
std::string tag;

std::string::size_type pos = line.find(' ');
if(pos != std::string::npos)
{
   // first space found.  So extract the first word
   tag = line.substr(0,pos);
}

Now, use code similar to above to find the '=' symbol, and extract everything after that. You will also want to skip all the spaces between '=' and the first non-white-space character.

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

fix the overflow first then rerun your program. Overflows scribble all over memory and can cause problems in the most unexpected places.

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

see win32 api function ShowWindow()

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

Lets start with main() function.

Line 96: you can not put function calls where variable names are expected. clrscr() is a function call to clear the screen but you preceeded it with the variable type declaration char. If your compiler supports clrscr() function and you want to clear the screen then remove the char variable type declaration.

lines 98, 99 and 100. I have no idea what your intent is here. int is integer variable type, such as they are whole numbers. After the int data type you need to put a variable name, not a character string.

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

you mean if the data is already sorted, not the sort function. :)

You have to iterate through the array and check if any element is not in order.

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

Line 19 -- change || (or) to && (and) logical operator.

[edit]Sorry Aia -- didn't see your post[/edit]

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

That for loop will iterate 11 times, not 10. 0, 1, 2, 3, ... 10 are 11 numbers. Either increase the size of vec to 11 or correct the loop.

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

Oh, then I'd suggest reading this I really don't know that much about it either, never had the occasion to use it.

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

can some one please help me? I am trying to find a best case, worst case and average case in a sorting function. I have no idea how to go about doing that, can some one please help me?

I think you will need several different sort algorithms, such as compare bubble sort with quick sort and several others. You have to code each sort algorithm then run the same set of data through each sort method, placing timers before and after to get the amount of time it takes for the algorithm to sort the data. Because computers do their work so quickly you will have to run each sort algorithm 1,000 or more times and to get measurable amount of time. Here's an example

clock_t startTime, endTime, deltaTime;

// time the bubble sort algorithm
startTime = clock(); // start the timer
for(int i = 0; i < 10000; i++)
     DoBubbleSort( <parameters here> );
endTime = clock(); // end the timer
deltaTime = endTime - startTime;
printf("Bubble sort took %u time\n", deltaTime);

now do each of the other algorithms the same way

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

I reformatted your code so that I could read it. Your compiler should have produced errors on lines 35 and 37 because variable numbers is an array, not a single integer. Correct all the compile errors before attempting to go on with the assignment.

#include<stdio.h> 
#include <stdlib.h>

void quickSort(int numbers[], int first, int last)
{
    int i, pivot, left, right, mid;
    int passes = last - first;
    if (passes > 0)
    {
        if (numbers[first] > numbers[last])
            swap(&numbers[first], &numbers[last]);
        if (passes > 1)
        {
            for (i = first + 1; i < last; i++)
            {
                if (numbers[i] < numbers[first])
                    swap(numbers[i], &numbers[first]);
                else if (numbers[i] > numbers[last])
                    swap (&numbers[i], &numbers[last]);
            }
            if (passes > 2)
            { 
                mid = (numbers[first] + numbers[last]) / 2;
                pivot = numbers[first + 1];

                for (i = first + 2; i < last; i++)
                {
                    if (abs(numbers[i] - mid) < abs(pivot - mid))
                        pivot = numbers[i];
                }
                left = first + 1;
                right = last - 1;
                while (left < right)
                {
                    while(numbers < pivot)
                        left++;
                    while (numbers > pivot)
                        right--;
                    if (left < right)
                        swap(&numbers, &numbers);
                    if (numbers == pivot && numbers == pivot)
                        left++;
                }
                quickSort(numbers, first + 1, right - 1);
                quickSort(numbers, right + 1, last - 1);
            }
        }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

assuming jobNo is the priority number, if it isn't then you will have to add another variable to the structure that is the priority of that node. I didn't attempt to compile or test this, so use it at your own risk :S

void linkedList::insert(shortint theID)
{
    liData *newItem = new liData;
    newItem->PrintItem.jobNo = theID;
    // find the insertion poit of the new node
    liData *prev = NULL;
    liData *temp = NULL;
    for(temp = ptrHead; temp->ptrNext != NULL; temp = temp->ptrHead)
    {
          // is new node's priority less than current node pointer's priority?
          if(newItem->PrintItem.jobNo <  temp->PrintItem.jobNo)
          {
              if(prev == NULL)
              {
                    // add new node at the head
                    newItem->ptrNext = temp;
                    ptrHead = newItem;
                    break;
              }
              else
              {
                    // add new node somewhere in the middle of the list
                    newItem->ptrNext = temp;
                    prev->ptrNext = newItem;
                    break;
               }
               // save current node address
               prev = temp;
    }
     // if it gets to here then all the nodes in the list have the same
     // priority as the new node.  So just add the new node to the 
     // head of the list.
     newItem->ptrNext = ptrHead;    
    ptrHead = newItem;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

josh --> vinod --> christna --> keep it more pleasant, stop the name calling/nation bashing. This is a public board which is read by everyone and some people think your comments are offensive. If you want to get involved in that sort of talk then please use PM or send each other e-mails, but not on this public board.

christina>you commented: . -1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The test in line 29 can never ever be true because the line just before it set k equal to j. Move line 27 to after line 34 and see if that helps.

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

what's wrong with it?

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

Use a for loop rather than while. you can control more the flow of your program if it is in for loop

A for loop is not appropriate here -- there is nothing to be incremented and need to loop an infinite number of times until specified condition is met.

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

it won't matter how many spaces are between the marker and the '=' symbol. After reading the whole line into memory take the first word (which starts with the first space on the line). If its the marker you want search for the '=' symbol and the text you want follows that (ignoring the spaces between '=' and the text).