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

there is no such index value as company[15], the indices are numbered 0, 1, 2, ... 14. A safer loop is to use integer, not pointer, in the for statement. Attempting to use ptr like you did is not safe because it depends on how the computer's memory is laid out

for(int i = 0, ptr = company; i < 15; i++, ptr++)
{

|

Finally, declare a const int to represent the number of elements in company so that you can easily change its value whenever you wish with little effort.

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

If you marked the thread solved and later find that you have more questions about the same topic you can change the thread to unsolved then continue the discussion.

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

My question is, can I change them into a single variable EACH?

Yes, declare three strings, assign some value to them, then compare if the if statement

Test the program I posted to see if it works for you.

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

There is no difference as far as efficiency, references are actually implemented as pointers. The difference is in safety because references can not be changed once set.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. PC, mem_CARD, soft_WARE, and disk_DRIVE should be an int, not double because you can't by a fraction of those items, whole numbers only. Use the data type that is appropriate for the thing you want it to represent.

mem_CARD + MEMORY_CARD

You need to multiply those numbers, not add them. * multiplies

I also dont understand why the code text is not showing up in the different colors that its supposed

Each editor has its own way to color-code c++ text, don't expect all editors to look like Turbo C

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

I posted sudo code that accomplishes that. And DavidB posted a complete program. What more do you want? Maybe you just don't understand what we posted. Put David's program into your compiler's editor, compile it, then run it to find out for yourself what it does. Then compare the program you posted with David's.

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

Correct solution but you shouldn't do people's homework for them, no matter how tempting it is.

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

Why use an array? Just sum the numbers as they are entered then print the result when finished, no need to keep them.

start of loop
   enter a number
   if number less than 0?  if yes then exit the loop
   sum = sum + value of number entered
end of loop
print value of sum
NathanOliver commented: Thanks. I over thought that +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program could be improved by better use of if statements and using only two FILE*pointers.

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


int main()
{
      int opt,opt1,a;
      int x, index;
      char fn[15],ln[15],sn[15],data[15],line[225];
      char locate[15];
      FILE *fp1, *fp2;
      char* filename;

      printf("\t\t\t\t*****MENU*****");
      printf("\n\n\n");
      printf("\t\t\t\t***STUDENT PROFILE***\n\n");

      fp1=fopen("2003.txt","r");
      printf("2003 Student Enrollies\n\n");
      printf("Student Number \t\tFirst Name \t\tLast Name\n\n");

      printf("\n\nEnter Data to Display: ");
      scanf("%s",&data);
      while( fscanf(fp1,"%s\t%s\t%s\n",&sn,&fn,&ln) > 0)
      {
            printf("\n%s\t\t\t%s\t\t\t%s",sn,fn,ln);
            system("cls");
            index = 0;
           if((strcmpi(data,"1234")==0)||(strcmpi(data,"John")==0)||(strcmpi(data,"Doend")==0))
               filename = "03/1234.txt";
           else if((strcmpi(data,"3214")==0)||(strcmpi(data,"Jane")==0)||(strcmpi(data,"Dredy")==0))
               filename = "03/3214.txt";
           else if((strcmpi(data,"2104")==0)||(strcmpi(data,"Joey")==0)||(strcmpi(data,"Drone")==0))
               filename = "03/2104.txt";

           fp2=fopen(filename,"r");
           while(fgets(line, sizeof(line), fp2) != NULL)
           { 
                 printf("%s",line);
           }
           fclose(fp2);
      }
      fclose(fp1);
      printf("\n\n");
      system("pause");

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

use fgets() to read an entire line at one time. But since you are using c++ you really need to learn the <fstream> and <string> library fuctions.

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

int main()
{
FILE *fp1;
char line[255];
fp1=fopen("data1.txt","r");
while(fgets(line, sizeof(line), fp1) != NULL)
{ 
     printf("%s ",line);
}
fclose(fp1);
printf("\n\n");
system("pause");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What compiler are you using? Learn to use your compiler's debugger so that you can step through the program and find out for yourself what is causing the problem.

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

The smallest unit of storage in a computer is one byte. What you want to do is to bitmap the byte(s) of memory, one byte normally holds 8 bits (but may vary depending on the operating system). So if you want an 8x8 matrix of bit then use an array of 8 unsigned char, e.g. unsigned char bits[8], then you can use shift operator and/or the & and | operators to set/clear specific bits.

Another way to do it is to define a structure that contains the bits

struct bits
{
   unsigned char b1:1; // bit 0
   unsigned char b2:2; // bit 1
   // etc for 8 bits
 }

 struct bits bitArray[8];

With the above structure you can set/clear bits by using the bit name instead of shifting. Example: bitArray[0].b1 = 1; // set bit 0

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

I compiled your program with vc ++ 2012 and, after changing a couple things to make it compatible with new compilers, it worked as expected for me. I don't have Turbo C so I can't tell you if its your compiler or not that is causing the problem. Or maybe you just misunderstand how the program is supposed to work correctly.

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

I've never seen Dirent.h or any of those includes before.

You will see them a lot when you do *nix programming. Just like you see windows.h when doing Ms-Windows programming. C is the standard implementation of os interface functions because almost all other languages can call them. c++ functions can only be called by c++.

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

If you want cross-platform then use c++ boost libraries

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

int raw_len = sizeof(MyTest_u_char2) + 1;

That line is wrong -- sizeof takes the size of a pointer, not the number of bytes allocated to the pointer. In this case sizeof(any pointer) is 4 (in most implementations today but could be some other value depending on your compiler). What you want is the const 8. Better to declare a const int for that and use it throughout so that you don't have to repeat magic numbers all over your program.

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

can you please write a program for me

Nice of you to ask, but No, we are not here to do your homework for you.

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

There are several higher-level c++ alternatives, such as C#, Windows Forms (which is CLI/C++), MFC, wxWindows, QT (cross-platform) just to mention a few. C#, WF, and MFC you will want to use Microsoft's VC++ 20?? compiler/IDE.

sss93 commented: Thanks I know but I would prefer learning more of the lower level aspects and making it work to my needs , Ive looked at c# and it seems much simpler and less tedious....however I more interested in accomplishing my goals in C++ +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. EnumWindows()

  2. See my previous post about gdi functions, especially BitBit()

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

read this article for keyboard input

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

Maybe a map is not the best way to go about that. Another way is to create a structure that contains a string for the argv entry and int for counter, then create a vector of those structures. After that, just call std::sort() to sort any way you want it.

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

yes it is opossible, how to do it depends on the operating system. For MS-Windows you need to learn win32 api functions. Here is a good tutorial. After you have learned that you can start learning MS-Windows GDI functions

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

wprinf() and related functions work with unicode characters. You may have to change the code page in order for other languages to display correctly.

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

int and const int are not the same thing -- int is a variable that can change a runtime from one value to another, while const int may not even be given storage because the compiler may just treat it as if it were a macro by inserting its value wherever it is used.

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

The reason you need the parentheses in the macro is so that you can call the macro with something like this: mult(2+5,10/2) it will look like this when expanced
2+5*10/2 = 2 + 50/2 = 2 + 25 = 27, which is not the correct answer.

Inline functions don't have the above problem.

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

The first one. macros are evil creatures. The macro is wrong anyway. should be like this: #define mult(x,y)(x)*(y)

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

Since all the cells have different values the only way to do it is in a loop, incrementing the cell values one at a time.

Are they all incrementing values like you posted? I suspect they are not because if they were then you would not need the array.

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

I gave you a link to a chart that has all the hex codes. All you have to do is look in the column titled "HEX", find the code, then look look in the column named Symbol. Any 5-year-old can do that.

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

Compilers are not required to honor the inline keyword, so the first example is guarenteed to be the fastest. The other two examples may or may not be the same timing, depending on the compiler.

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

<deleted>

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

(5/9) is doing integer division, not floating point division, which means that all fractions are lost, so the result of that is 0. To correct that problem add a decimal point, e.g. (5.0/9.0) or (5.0/9) or (5/9.0). As long as numerator or denominator or both are floating point numbers it will do floating point math.

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

You can easily do it yourself. Just look up those hex numbers in any ascii chart

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

The results make sense -- vectors have a lot of overhead that take cpu cycles, more time than just doing the calculations. The program has to make other calculations just to access the vector item.

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

Sorry, but killing someone is never funny or humorous, except maybe in a cartoon like RoadRunner where the person or other living creature is not really killed.

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

delete lines 14 and 26, the continhue statement is not needed

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

What was you expecting time_t to contain? If struct tm is correct then the value for time_t is also probably correct. Recall from our previous discussion in this thread that time() returns time_t that is the number of seconds since some pre-determined date, quite often 1 Jan 1970, but that date can be anything the compiler wants it to be.

If that's not what you are wanting, then you could calculate it yourself by setting it to the number of seconds since midnight of the current day. Just convert HH and MM to seconds. The problem with that approach is that it makes it pretty difficult to find the difference between two times because the two times may or may not be on different dates.

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

Can we make it "17:30" now

If you want the time_t converted back to a string then call strftime() to create the string, which works a little bit like printf()

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

you also need to set a year/month/day because time_t is the number of seconds since 1 Jan 1970 to the specified date.

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

I call mktime(). One crevet -- you need to initialize all fields of struct tm to 0 before using it becuse mktime() will return an error of any of the fields contain random junk values. Here's an easy/quick way to do that.

struct tm tm;
memset(&tm,0,sizeof(struct tm));
WaltP commented: A crucible or melting pot? Or did you mean caveat? ;o) +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

x['a']=0;

Yes it can be done, but the array must be large enough for 'a' to be a valid index value. That may be useful when you need to count the frequency that each letter occurs in a sentence or other text document. You need to declar the array like this: int x[255] = {0};

In c++ it would be better to use a map as previously suggested.

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

line 18: should be text[i] != ' '. You used the wrong loop counter.

After line 23 you should advance i counter until text[i] != space so that there can be more than one space between words

line 15: gets() is a bad function to use becuse it will allow you to type more characters then the buffer can hold, causing your program to crash. Instead of gets() use fgets() so that input length of limited to no more than buffer size. fgets(text, sizeof(text), stdin);

tmp->word[m]=*(y+m);

lines 34-38: Too compilicated. Just call strcpy() which doesn't need as loop. Unless of course if you are not allowed to use strcpy()

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

The contents of the queue are char*, you can't mix it with std::string

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

Not in C or C++. Index values must be positive.

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

You don't use strcmp with std::string, instead std::string has == operator that returns true if the two strings are equal, false otherwise. for example

std::string s = "Hello";
if( s == "HELLO" )
{

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

If you'r a mod, admin, or paid subscriber you can set your rank to say anything you want (within the bounds of DaniWeb rules of course)

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

you have to hover mouse over up arrow, add comments in box, then click up arrow. You can't click upp arrow first becuse the second time the rep will change from 1 to 0.

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

what STL container did you use?

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

If you declare the array like that: char* command[25]. Otherwise you can do his: conrol(int n, char** command). Note: variable names are NOT usually in UPPER CASE.

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

char command[] is just a simple array of characters, or a single string such as "Hello". You can't store multiple strings all at the same time in it.

char* command[] is an array of pointers to strings, which is what you need for your program. Another way to express it is char** command.

All older compiler require a constant integer to expres the number of elments in array, such as char* command[20]. The newest C standard also allows it to be a variable, such as char* command[argv]. You might have to test it to find out which form your compiler supports. Which ever way your compiler accepts you have to be consistent throught the program, don't use char** command in one place then char* command[] in another because the compiler will complain about that too.

If you are still confused about pointers then maybe you should study this tutorial.

piero.costa commented: perfect awnser! +0