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

You heard wrong. Labor Day was yesterday -- Monday.

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

>>actually the fscanf statement reads the entire line #include<stdio.h>(
But it will not work if there are any spaces anywhere in that line. Put a space between #include and <stdio.h> and see what happens to your program.

>>but i checked my code working correctly in TURBO c
That's only because turbo c is an ancient, outdated, archaic compiler that doesn't know any better.

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

why don't you just have the threads that's downloading the file tell the other thread how much of the file it has downloaded? If you are using sockets the thread that is doing the downloading must know how many bytes it has downloaded, unless of course you are using some library that hids that information from it.

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

Thanks for your response to a three-year-old thread :)

For anyone else who stumples upon this thread, I don't recomment Dev-C++ any more because its a dead IDE and uses an old compiler. Get Code::Blocks.

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

scnaf(%s stops processing keyboard input when it encounters the first space. If you want to include space when use fgets() instead of scanf()

fgets(name, sizeof(name), stdin);
// now remove the trailing carrage return '\n'
if( name[strlen(name)-1] == '\n')
   name[strlen(name)-1] = '\0';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, I wrote a test program of my own using his bubble sort algorithm that he posted, and it worked ok. So there must be something else in his program that is incorrect. The problem might be that he passed the vector by value instead of by reference to that bubble sort function.

@Nervous: You will have to post the rest of the program before we can answer your question.

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

Yes, calculating the average is probably taught in grade school. Most 12-year-old kids can probably tell you how to do that.

The problem in C programs is not how to do it on paper, but how to tell the computer (who is an idot) how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
char mnumber[255];
printf("Enter an item number\n");
fgets(mnumber,sizeof(mnumber), stdin);
if( mnumber[strlen(mnumber)-1] == '\n')
   mnumber[strlen(mnumber)-1] = '\0';
printf("Meter number is: %s\n", mnumber);

Or if you want the c++ version

std::string mnumber;
cout << "Enter an item number\n";
getline(cin,mnumber);
cout << "Meter number is: " << mnumber << '\n';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's the bubble sort I learned many many years ago. It's a more optimized version of the algorithm NervousWreck posted because it does not require as many comparisons. There are several bubble sort algorithms -- here is another.

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

a character array or std::string

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

You can't do that directly in C or C++. What I would do is create a structure that contains the variable name and value

struct item
{
   std::string name;
   int value;
};

Then you can have a vector of those variables vector<item> data; Another way to do it is to use std::map to map the variable name and integer value.

#include <string>
#include <map>
using std::string;
using std::map;

int main()
{
    std::map <string, int> data;
    data["a"] = 1;
    data["b"] = 2;
    data["c"] = 3;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is an article you might want to study

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

Do you have to write your own sort algorithm? If not, then just use std::sort() which is declared in <algorithm> header file

As for your program: I think the loops are wrong. And there is no need for strcmp()

int len = deansList.size();
for(int i = 0; i < (len-1); i++)
{
   for(int j = i+1; j < len; j++)
   {
       if( deansList[i].lastName > deansList[j].lastName)
       {

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

try c# or c++/CLR

NicAx64 commented: sorry sir no CLR no .Net I'm working for a company which implements Linux based soultions,to our customers. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program has at least a few problems
>>void main()

It's int main(), even though ancient compilers such as Turbo C allow it.


>>while(!feof(fp))
eof() doesn't work like that and will cause that loop to execute too many times.

>>strstr
If you are going to use scanf() then there is no point using strstr() because the character buffer will only contain one word. strstr() is a waste of time in this situation. Just use strcmp().

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

>>put in a table

C language does not use tables. It has arrays.

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

Today is a Labor Day holiday in USA.

Labor Day, the first Monday in September, is a creation of the labor movement and is dedicated to the social and economic achievements of American workers. It constitutes a yearly national tribute to the contributions workers have made to the strength, prosperity, and well-being of our country.

Today its just a holiday for beer and barbecue. Sadly, with high unemployment, many people don't have much to celebrate about.

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

Sorry, I don't understand your question.

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

winzip can not read that file.

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

Learn to use your compiler's excellent debugger and find out where the problem occurs. Also try to remove those compiler warnings about converting double return value to int.

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

Depends on what you mean by GUI. If you mean MFC then you just buy the Professional version. If you are not going to use MFC then you might be able to get along with the free Express version and download some free libraries that let you write gui programs, such as wxWidgets. There are also Express editions of c++/CLR (Windows Forms), C# and VB.NET.

Before spending hundreds or thousands of dollars for something you don't need check out the free versions to see if they do what you want.

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

The only suggestion would be to processess the messages in another thread.

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

Your question is like calling up the auto repairman and saying "my car is broke. Do you know what's wrong with it?"

We need a lot more information, such as the source code for the program.

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

The asterisk before the variable means to reference only the first character in the string that the variable points to. So if string = "1234", then *string is looking at '1'. Another way to say the same thing is *string it the same as string[0].

Consequently, *string - '0' is the same as '1' - '0', which if you look at any ascii chart '1' = 49, and '0' = 48. So it boils down to 49 - 48 = 1.

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

There is no programmable fix for stupid. The programmer of the application which uses your library will probably find it out if he attempts to do things as dumb as you described. Good function documentation should be all that you need to do. See Narue's avatar :)

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

duplicate. see other thread for answers.

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

I much perfer this instead of all those shifts. The code below could fail for integer overflow.

int myatoi(const char *string){
   int i = 0;
    // skip leading white space
   while( isspace(*string))
      ++string;
   while(*string && isdigit(*string))
   {
       i = (i * 10) + *string - '0';
       ++string;
   }
   return i;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are more disadvantages than advantages to using inline assembly in c++ programs. I used to use inline assembly 20 years ago in old MS-DOS programs but that was because compilers were not very smart in those days. But today I wouldn't even consider it. Compilers are pretty damned good, and portability is a big issue now.

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

>> Can C++ do graphics?
Yes

>> Can C++ do networking?
Yes

>>Does C++ contain every data structure that one would need?
Yes, and if it doesn't the programmer can create his/her own

>>Is C++ easy to learn?
Subjective. Depends on who is learning it. Some yes, and others no.

>>Are there defects in C++?
Subjective. Depends on what you call a defect. IMO no.

>> its hardly the best tool to use in most applications.
I would agree that c++ is not the best tool in all applications. There are things that are easier to accomplish in other languages, but c and c++ can do it all.

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

variable element is not a class, its a T* (or int* as used in the test program).

MyVector<int> numbers;

template <class T>
class MyVector : public arrayList<T>


template<class T>
class arrayList : public linearList<T>
{
T* element; // 1D array to hold list elements
};

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

>>Well I got it wrong.

Why was you wrong? New programming languages has nothing to do with how bad or good c and c++ are.

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

>>can't figure out what I'm doing wrong
That doesn't surprise me since you can't even figure out where to post this question.

diafol commented: ha ha ha - his first and last post I take it. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Good Evening

What? did I sleep through the entire Sunday? It's early afternoon where I live. :)

Welcome to DaniWeb anyway.

>>I was also wondering if there was a 3D/Animation section here
No. That's not to say there aren't people here who can discuss it with you here at DaniWeb. It won't be me though because I never did any of that.

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

>> NewList->key=(char *)malloc(sizeof(key));

sizeof() operator does not return the same thing as strlen() function. All sizeof will give you for a pointer is the size of the pointer, not what the pointer contains. So what you want is NewList->key=(char *)malloc(strlen(key)+1);

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

I think the original site is gone now -- the only place I can find it is here and here and here.

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

Of course you have the answer. The answer is: it may be compiler dependent. But for MinGW and VC++ 2010 express there is no difference in speed.

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

program statements have to be written in logical sequence. For example you can not add LetterGrade to Sum before you know the value of LetterGrade. And LetterGrade has to be converted from A to F into numeric value befor it can be added to Sum.

char LetterGrade = 'A';
int number;
int Sum = 0;
while(LetterGrade != '0')
{
    cout << "Enter Letter Grade: ";
    cin >> LetterGrade;
    switch(LetterGrade)
    {
      case 'A': number = 100; break;
      // other case statements go here for each grade
    }
    Sum += number;
    Counter++;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are you using? Your program compiles without error on vc++ 2010 express.

replace getchar() with cin.get()

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

We're not going to do your homework for you.

(1) if the head is NULL -- this is a simple assignment statement. allocate memory for the new node then assign its pointer to the list's head.

(2) head already exists: You want to add the new node to the tail of the list. The function needs to iterate through the nodes to find the last node, then assign the new node to the next pointer of the tail node. That makes the new node the new tail node.

(3) It doesn't matter what the node contains, the above two methods are always done the same way.

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

If no optimisation took place, that would be the case, yes.

I think we have proven, for two compilers that statement is incorrect. The only difference between p++ and p = p + 1 is personal preference (or company coding standards).

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

So MinGW produces the same code too. But you can't compare the results of vc++2010 with yours because the c programs are not the same. The program I posted uses a pointer while yours just uses an integer. Try making your code use a pointer and see the result asm code.

I changed mine to use an int instead of a pointer and the compiler produced the same code as before, but this time added 1. It did not use the inc assembly operator.

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

Ok, so Product Review is another name for Spam :)

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

is this a hidden menu? I found a thread in it by clicking "New Posts", but I can't find it using Community Center menu. I was going to flag this post as spam, but so sure now.

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

total+=y is the same as total = total + y. Just a shorthand way of saying it and either is perfectly acceptable.

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

did you try this?

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

or else u can do with strlen

for(i=0;i<strlen(s);i++)

You could, but you should never use strlen(s) in a loop like that unless the length of the string changes somewhere inside that loop. Why? Because the program has to call strlen() function on every loop iteration, whould could be very very time consuming, making your program slow.

Instead, either check for the string's null terminating character as previously posted, or set an int to the value returned by strlen() and use it in the loop.

int len = strlen(s);
for(i = 0; i < len; i++)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Even without optimization it will be compiler dependent. You can test that out for yourself by having your compiler generate the assembly code and see for yourself what it does with it.

int main()
{
    int x[5] = {1,2,3,4,5};
    int* p = x;
    p++;
    p = p + 1;
    p += 1;
}

With vc++ 2010 express the assembly/machine code generated is below. Notice that all three produce identical code.

; 9    :     int* p = x;

  0004b	8d 45 e4	 lea	 eax, DWORD PTR _x$[ebp]
  0004e	89 45 d8	 mov	 DWORD PTR _p$[ebp], eax

; 10   :     p++;

  00051	8b 45 d8	 mov	 eax, DWORD PTR _p$[ebp]
  00054	83 c0 04	 add	 eax, 4
  00057	89 45 d8	 mov	 DWORD PTR _p$[ebp], eax

; 11   :     p = p + 1;

  0005a	8b 45 d8	 mov	 eax, DWORD PTR _p$[ebp]
  0005d	83 c0 04	 add	 eax, 4
  00060	89 45 d8	 mov	 DWORD PTR _p$[ebp], eax

; 12   :     p += 1;

  00063	8b 45 d8	 mov	 eax, DWORD PTR _p$[ebp]
  00066	83 c0 04	 add	 eax, 4
  00069	89 45 d8	 mov	 DWORD PTR _p$[ebp], eax

; 13   : }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Another name for it is "cursor". But MS-Windows calls it a caret for some ungodly reason. I always though a caret was something we eat.

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

Ok, here is a simple example that I whipped up in just a few minutes. It creates a vector of people structures then calls std::search_b() to find one of the objects.

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

struct person
{
    string fname;
    string lname;
    void init(const char* f, const char*l)
    {
        fname = f;
        lname = l;
    }
};

bool compare1(person& p1, const char* value)
{
    return p1.fname == value;
}

bool compare2(person& p1, const char* value)
{
    return p1.lname == value;
}

int main()
{
    vector<person> people;
    person p;
    p.init("Jones","Tom");
    people.push_back(p);
    p.init("smith","Mary");
    people.push_back(p);
    p.init("Adams","Tom");
    people.push_back(p);
    p.init("Baker","Henry");
    people.push_back(p);
    vector<person>::iterator it = search_n(people.begin(),people.end(),1,"smith",compare1);
    if( it == people.end() )
    {
        cout << "Not found\n";
    }
    else
    {
        cout << "Found\n";
    }
	return 0;
}