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

You're using the wrong compiler. What you have is old and buggy. Replace it with Code::Blocks, whieh is current . You will want the version that is supplied with MinGW compiler.

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

Confused as always. malloc returns void * , which of course can be typecasted to anything.

.

I didn't say void* can't be typecast to anything. I said it int* can't be typecast to char*. int* x = (char *)malloc(sizeof(int)); Please read and comprehend before you look like a fool.

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

could not is correct -- meaning that if you did it then the compiler should probably produce an error for wrong typecast. (can not convert char* to int*, or something like that)

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

You mean search programs similar to *nix grep? There already is a MS-Winows port of grep, which is adequate for all my needs.

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

>> Yes the program is open source but I dont wanna compile

How do you expect to accomplish the goals you posted if you don't recompile the program???? :icon_eek:

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

In C language the return value from malloc() does not need to be typecast at all. But if you do use typecast then it needs to be typecast to the appropriate type. For example the line 3 you posted the return value of malloc could not be typecast as char* because that it the wrong type.

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

Read this wiki article. I have never actuall come across such a hardware myself, at least not that I know of.

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

Read Chariots of the Gods book. Or see this video. They will explain the whole thing to you in stunning detail.

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

>>assignment_2_v1.c:60:4: error: stray ‘\302’ in program

I have seen something like that before -- its caused by some unprintable character on a line. The way I fixed it was to delete the line and retype it.

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

>>for(t=0; t<&numberOfThreads; t++)

That is attempting to compare integer t with a pointer to numberOfThreads. Why the pointer? Remove the & pointer operator and it will be ok.

line 60: void functions can not return a value.

lines 63 and 64 are not inside any function. Format your code better and you would easily see that.

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

I assume you already know enough assembly language to at least start that project. Teachers don't just toss a project like that at on the first day of class. So, get started and post what you have done. You will probably want to write some pseudo code first so that you understand the problem and possible solutions better.

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

Ancient Dragon, I wasn't asking a question. I just replied to the other person, and I wasn't even talking to you. Based from the other threads I created here, I noticed you get hot-headed too quickly, maybe you could just stop replying if you have no input to share. I appreciate your previous replies just as much as your silence when you're not the one being talked to.

It's just annoying when people give answers and the original poster, like you, just ignore those answers. Do you want someone to write the program for you? If you do then you are at the wrong web site. You have already been given enough ideas how to do it, so its up to you to get on with it and start coding. Once you do that you will understand the solution better.

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

It took several years before I could write C code without use of a very good reference book next to my computer. I was constantly looking up functions and their parameters just to make sure I was coding it correctly. Then I learned to use debuggers and how to use them to quickly figure out problems with the code I wrote.

I don't see that effort much here at DaniWeb. Many students don't want to put in the time and effort needed to learn a language. Instead they want other people to spoon-feed the answers.

Another problem I see here occasionally is someone who doesn't understand the answers they are given. They ask a question, one or two people offer correct solutions, but the OP asks the same question again because they didn't understand the answers given.

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

I have no idea -- never heard of the term, for whatever that's worth.

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

I'd go crazy in retirement, personally. I can't imagine not having a job, or something to "get done" every day for more than a month.
More power to those that can enjoy that sorta life.... I just get bored, and lose my sense of purpose when i sit and rot away for too long.
You can only collect so many star trek comics, and pick up so many hobbies before you get bored.

I agree. I retired, and a week later I got another PT job to keep from getting so bored. And that is one reason young people have a difficult time finding employment -- too many old people still working, and its only going to get worse as our population ages. You can thank moderm medicine and great medical doctors for that.

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

students include kids from ages 4 to 104. Anyone attending a school is a student. Strictly speaking, other people are often students as well, such as those attending one-time technical training courses.

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

Not likely that will work. Sounds more like a hardware problem. Just buy another CD/DVD and replace the thing. I don't know about other countries but in USA they almost give them away.

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

You know what has to be done, so now all you have to do is stop asking the same question over and over and get to coding it. Its a very simple loop as previously illustrated.

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

>>I was under the impression that 8bits = 1byte is a universally accepted measurement,

Nope -- there are 4 and 7 bit byte hardware, but 8 bit is probably the most common.

>>But I want to read bits.
Impossible. You have to read bytes and then extract bits in memory.

>>This is exactly why I'm looking for a system that does not involve more than one variable to hold the data

You won't find it on MS-Windows, MS-DOS, or *nix systems because they have not invented those things yet. You might try IBM mainframe -- but you may have to pay a few million dollars to get it.

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

You may say that using embedded systems to provide examples of implementations that won't behave "normally" is a bit of a cheat since very few embedded systems are even remotely standard compliant, well, you asked for examples, you got some.

I asked for examples of *nix and MS-Windows. Said nothing about embedded because I already know they are different, and many of them don't support time functions. Many more embedded don't even support C language programs.

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

Oh yes -- I see it now. I mis-read it. I was assuming time_t was defined as size_t, which it is not. That's what I get for trying to read the standards -- and arguing a point with Narue :)

The fact remains -- show me a compiler (*nix or MS-Windows) where time_t does not represent the number of seconds since 1 Jan 1970. I don't think one exists. Therefore this discussion is all just academic.

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

>>The standard says nothing about time_t being synonymous with size_t.

Funny -- I posted the quote from the C standards. 7.23 "The types declared are size_t"

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

>>No. You are claiming that all implementations of time() are the same

Where did I say that? I just said *nix and MS-Windows. Show me a compiler that has some other implementation on either of these operating systems. The C standards say time() returns time_t, and that time_t is a numeric data type represented by size_t. Section 7.17 states that size_t is an unsigned integer type. So according to standards it is not possible for time() to return anything other than an unsigned integer type. Now, how that unsigned integer is constructed is not specified but its common practice for it to be the number of seconds since epoch. Borland, Microsoft, IBM, and GNU compilers all encode it as the number of seconds since 1 Jan 1970.

7.23 Date and time <time.h>
3 The types declared are size_t (described in 7.17);
clock_t
and
time_t
which are arithmetic types capable of representing times;
and
struct tm

7.23.2.4 The time function
Synopsis
1 #include <time.h>
time_t time(time_t *timer);
Description
2 The time function determines the current calendar time. The encoding of the value is
unspecified.
Returns
3 The time function returns the implementation’s best approximation to the current
calendar time. The value (time_t)(-1) is returned if the calendar time is not
available. If timer is not a null pointer, the return value is also assigned to the object it

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

>>Prove it.

Its up to you to disprove it. Show me an implementation of MS-Windows or *nix where its not true and I'll gladly eat my words. Although you are technically correct there is no point in arguing about something that doesn't exist.

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

The implementation of time() is the same on both *nix and MS-Windows, which I think we can safely assume will be the operating system of choice for 99% of the members here at DaniWeb.

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

>>Ok, so time() function (argument being null) returns what?

It returns the number of seconds since 1970, as you previously posted. It doesn't matter whether the parameter is NULL or not, it will always return the same value.

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

pseudo code

do {
   does search string exist in long string?
   No -- then exit the loop
   replace search string with replacement string
} // end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

who said aliens were logical like us? All (or most) humans have two arms and two legs, yet there is no relationship between you and me other than we are both earthlings.

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

No command. You have the write the code to do that yourself. Write down on a piece of paper the original string. Then using your pencil try to delete and insert the new text. Doing that visually may help you to understand more clearly how it might be done with a computer program. You will most likely need to use another chracter array for temporary storage of the string fragments.

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

probably gremlins have gotten into your computer.

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

If you are looking for a book and have the money then this is a good one to buy.

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

Klingons

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

>>..how can i see the sorted number?

Print out the array after sorting and you will see for yourself whether your sort function worked correctly or not.

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

line 28: duplicate variable declaration

lines 73-to end of program -- all the code is outside a function. Function main() ends on line 71 and you never started another function.

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

1. Get the file size and divide by the size of each record. After opening the file, call seekg() to the end of the file, then tellg() to get the file size.

2. You don't need that loop on line 34. If you know the number of records then just use ifstream::read() to read the entire file into an array of structures all at one time. Of course you have to allocate an array of appropriate size beforehand.

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

The first error listed is the most important. The problem is more than likely caused by mis-matched brackets, probably missing a closing } somewhere. Start counting open/closing brackets to find out which one is missing.

You are also missing brackets around the multi-line else statement on line 64.

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

Yes, any function in one *.cpp can be called from functions in other *.cpp files. That's how multi-file projects work, and is identical approach taken when functions in the standard C or C++ libraries are called. What you will want to do is put all the function prototypes in a *.h file and include that *.h file in each of the *.cpp files.

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

Are you trying to be hip?

Sorry, I don't know the meaning of that word, other than it's some part of my body. The slang use of that word went out of style some 40+ years ago.

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

using one *.cpp as an include in another *.cpp is a BIT NO-NO. Create a project and add both *.cpp files to it. The compiler will compile each *.cpp file and then link them both together, along with other libraries that the program may use. You will see the advantage of this when you get a project that contains hundreds of *.cpp files.

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

\b = it's purpose is backspace
\r = purpose is carriage return

i want the purpose of for(;;)
please clear my doubt
thank you

for(;;) is an infinite loop and used where the number of iterations is unknown.

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

This is a prime example of why I hate typdef of plain-old-data-types. It's very difficult to keep track of what's a char* and what's a char**.

variable a is declared on line 9 as char**, and memory allocated for each rows on line 27. So far, so good. No problem with that. Huge problem on line 31 where the memory allocated on line 27 is destroyed and replaced by a char* returned by call to getStr(). Now there is a big memory leak.

line 101 is another memory leak. It delets a without deleting each of its rows. The resize() function has already copied all the strings in a to array b, so there is no reason to keep all the rows of array a

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

Then you need to start reading tutorials on how to write VB code. Here is a list of a whole bunch of tutorials.

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

I think our scientists already know there is no life on Mars, hence no such thing as a Martian. But that doesn't mean there isn't life on other planets, such as those encountered by Star Trek TV shows.

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

Sounds like you have to write a C program, not a C++ program. In that case I would use strtok() to split the line.

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

int main()
{
   char line[] = "shunt train2.in 2";
   char *verb, *filename, *ptr;
   int num;
   verb = strtok(line," ");
   filename = strtok(NULL," ");
   ptr = strtok(NULL," ");
   printf("%s %s %s\n", verb,filename,ptr);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try using stringstream class

#include <sstream>

...
std::string line = "8:30 AM";

int hour, minute;
std::string ampm;
char temp;
stringstream s(line);
s >> hour >> temp >> minute >> ampm;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The easiest way to do that would be to use stringstream class

#include <sstirng>
#include <string>
#include <fstream>
// other includes too

int main()
{
   std::string line = "shunt train2.in 2";
   std::string verb, filename;
   int num;
   strgingstream s(line);
   // now splie the line into its individual parts
   s >> verb >> filename >> num;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to write a function for each command you want to support

Next, read a line, split the line into its individual words, then call the appropriate function for the verb in the first part of the string. Something like this:

string verb;
string line;
size_t pos = line.find(' '); // find first word
verb = line.substr(0,pos);
if( verb == "spur")
   spur(line);
else if(verb == "shunt")
   shunt(line);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you want to rename main.h to myclass.h so that the name of the file tells you what's in the file. Other than that, there is little, if any, difference between the two methods. It's all a matter of programming style. I prefer the first method when one header file depends on another.

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

You have already done the hard part. What don't you understand about calculating the median? Just sort the array and select the value in the center of the array. There are many sorting algorithms, the easiest one (but also the slowest one) to code is the bubble sort.

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

Post what you tried.