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

depends on the operating system. MS-Windows uses boot.ini in the root directory.

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

you did something wrong because it didn't work

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

if that first loop is trying to count the number of words in the file, it won't work because words can be separated by one or more spaces or tabs. You don't need to count the number of words anyway. just change the second loop to read until fscanf() returns 0.

while( fscanf( fp1,"%s",text) > 0)
{
   // code here
}

also your program needs to close the file handles after finished reading the file.

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

something is probably corrupting the memory pool some place else in your program and that's a difficult problem to find. If you have a large progrm I would start by commenting out large blocks of code until the problem goes away. That at least narrows down the search.

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

Not noticing anything here, Ancient one.

neither have I since I posted that. Maybe the DaniWeb server is just busy at the time.

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

You don't need a while loop to print the spaces. Just use a variable instead of hard-coding the field width as in my previous example. Just replace the 20 with an asterisk and add the width variable

int width = 20;
printf("%*s", width, "Hello");

>>my other question is how can ve write quote (") on the screen.. ı cant do that

you have to use escape character befor it, like this: printf(" \"Hello\" ");

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

please how can i use bottons in C?

what operating system ? what compiler ? what GUI library ? There are hundreds of ways to do it depending on the answers to those questions. But in no case can you do it in text-mode window like the MS-DOS command prompt or *nix console.

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

1. never ever use gets() -- it can destroy your program at runtime if you enter more characters than the input buffer can hold. Use fgets() instead to limit input. The downside to that function is you have to remove the trailing '\n' charcter (the <Enter> key)

2. I assume the file contains floats and no other non-float characters. If that's the case then use fscanf() to read the floats then simply compare the value read to 0.7F.

float num;
while (fscanf(z,"%f",&num) > 0)
{
    if( num >= 0.7F)
       printf( <code here> );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is it just me or have others experienced extreme slowness in replying to threads?

It's back again. When I hit the submit button it takes a very long time to complete. Just started yesterday.

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

Read about the printf format string -- you can specify the field width for strings and whether they are left or right aligned.

int main()
{
	printf("%20s\n", "Hello");
	printf("%20s\n", "Hello World");
	return 0;
}

That will print the word "Hello" in a field that is 20 characters wide and right aligned. add a minus symbol before the 20 to make it left-aligned

why don't you use the standard c function strlen() instead of re-inventing the wheel? Or is it required by your instructor to do that?


Read Lerner's suggestions -- they are good ones.

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

>>Also I dont know how to switch the percantage
How would you do this with pencil and paper. If you buy a pencil for $1.00 and the taxes are 6 percent what it the total price? Hint: 1.00 plue 1.00 * 0.06. The same in your problem. If you enter 50, then the percentage is 50/100 or 0.5.

The formula (untested) should be something like this:

float number
float percentage

float answer = ((number-45.0) * (percentage/100)) / 2.0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what are the error(s) your compiler gives you ? A quick once-over looks like braces are missing from lines 26 and 38, and remove the semicolon on line 38.

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

haha...I got the URL....

You can remove everything now if you want

Dam! I wasn't fast enough:mrgreen:

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

post the code for what you know how to code and ask questions. We'll be glad to help, but we don't write it for you.

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

Microsoft MFC has a c++ socket classes, but I hear it isn't very well liked. You might check boost libraries, it probably has something.

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

If you don't want it to exit then what do you want it to do ? you can create a loop as below, but the problem with this is that there is no way to quit the program when you want it to.

int main(void)
{
   while(1)
   {
        printf("hello, world\n");

        fflush(stdout);
        getchar();
    }
}

Another method is to ask to enter 'Q' to quit

int main(void)
{
   int key;
   while(1)
   {
        printf("Enter 'Q' to quit");
        printf("hello, world\n");

        fflush(stdout);
        key = getchar();
        if(key == 'Q')
            break;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes the url was removed by the moderators.. I dont know why but may be the policies of dani restricts this.
Anyways.. I came to this forum to learn C++ in depth. Yes I know a lot in it but I think its stil not enough.

The Taj operating system is already being developed...

<url snipped>: this is the link. May be this time it wont be removed.

Yes, I removed the e-mail address and link. Read the rules and you will find out why we do that.

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

start by reading the Read Me threads at the top of this board.

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

use fgets() instead of fgetc() and your program will work better and be a lot less complicated.

delete line 5, NULL is defined in standard c header files.

remove the braces on lines 11, 12 and 13. They are not necessary there.

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

>>could you help me
Yes, but you will have to post your code first because I can't see your monitor.

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

Sorry, I misunderstood the question. you will find lots of information for beginners in the Read Me threads at the beginning of this board.

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

I get that message two or three times a day. Just now happened again in Site Management -->Posts Since Last Visit.

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

I don't think there is such a thing as a c++ video. do you mean mp3 files ??

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

It has little, if anything, to do with terminals. Just a method of terminating a text line in text files. I don't know why MAC and MS-DOS didn't follow *nix's lead and just save '\n' in the text file -- would seem the logical thing to do since most (but not necessarily all) lines read by fgets() terminate with '\n'. MAC and MS-DOS/MS-Windows os just have to do a little extra work to maintain that standard.

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

the code i posted will cause a buffer overflow on most compilers on a 32 bit architecture.


No -- it will create buffer overflow on every ansi standard compilant compiler, which is almost every c compiler in the world.

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

you have to use one of the convertion functions. Example:.

char val[] = "123";
int n = atoi(val);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The new line in the text file is operating-system dependent. *nix uses '\n', MAC uses '\r', and MS-DOS/MS-Windows uses two characters "\r\n". Which is why text files that are transferred between operating systems are often run through a translator to convert from one format to another.

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

Pass the structure as a pointer to the function

void Testing(PERSON* name)
{
     scanf("%s", name->individual[0].name);
}

and don't use scanf() for strings because, like gets(), it will cause buffer overflows if you type in more characters than the destination buffer can hold. Use fgets() instead

void Testing(PERSON* name)
{
    char* ptr = 0;
     fgets( name->individual[0].name, sizeof( name->individual[0].name), stdin);
     // now remove the '\n' if it exists in the input buffer
    if( (ptr = strchr(name->individual[0].name,'\n')) != NULL)
         *ptr = 0;
}
Aia commented: Great help -Aia :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just a particular category, such as "Coffee House".

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

First create an instance of the structure then populate each PERSONAL structure, for example to populate the first PERSONAL structure

PERSON person;
strcpy(person.individual[0].name,"Tom");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sometimes I get this error, if I try it again it works as expected.

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

OMG vijay where did you learn programming :eek: The code you posted still contains buffer overflow.

>>most compilers will allocate more memory than seems is necessary
for data
compiler-specific behavior and something you must never ever count on. talk about taking advantage of undefined behavior :eek:

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

If you would have to write your own implementation of the
function getchar() in C; how would you do it?.

It would have to be compiler and os specific which is why the C standards did not dictate how the function is to be implemented. You could use non-standard functions in conio.h like kbhit() and getch(), assuming your compiler supports those functions. For 32-bit programs that run under MS-Windows you could use the win32 api console functions. Don't know about MAC or *nix.

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

You cannot use C to solve this problem. The highest integer value it can use is: unsigned long (32 bits) goes from 0 to 4,294,967,295 max.

There are other languages that can handle very large integers easily.

not really necessary.
both 999 and 3*9*9*9 (max possible values)
are <= 1000.
int wouls suffice

yes, it doesn't even get close to maxing out the largest int value :eek:

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

.
So Fox made me tought that C++ programs compiled in VS need a framework,

you need the Framework for the compiler itself.

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

Ooooh:cheesy: ! Aaaaaaaa :cheesy: That's soooo cool!:eek:

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

Sudo: did you notice that you answered a year-old thread?? :mrgreen: :mrgreen:

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

Only managed programs (and C#) need the .NET framework. Pure c and c++ programs as well as MS-Windows applications do require .NET framework.

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

You cannot use C to solve this problem. The highest integer value it can use is: unsigned long (32 bits) goes from 0 to 4,294,967,295 max.

There are other languages that can handle very large integers easily.

I think most compilers support 64-bit integers nowdays (long long or __int64)

[edit] This works, which is what Vijayan posted. All I did was replaced int with longlong (VC++ 2005 used __int64) [/edit]

#include<stdio.h>
#include<math.h>
typedef __int64 LONGLONG;

LONGLONG value_digits( LONGLONG a, LONGLONG b, LONGLONG c ) { return a*100 + b*10 + c ; }
LONGLONG value_sum_power( LONGLONG a, LONGLONG b, LONGLONG c ) { return a*a*a + b*b*b + c*c*c ; }

int main()
{
  LONGLONG a,b,c,number;
  for( a=0 ; a<10 ; ++a )
  {
      for( b=0 ; b<10 ; ++b )
	  {
          for( c=0 ; c<10 ; ++c )
          {
            number = value_digits(a,b,c) ;
            if( number == value_sum_power(a,b,c) )
              printf( "%I64d\n", number ) ;
          }
	  }
  }

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

Aia is absolutely and positively correct. If we write the program for you then (1) we will not get the grade, you will and (2) you will learn nothing.

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

All the above. If you are new to c++ then you are not ready to tackle that project -- companies have spent years of manhours on that sort of project and those programmers are highly experienced people. database programs do not bring the entire files into memory because the files can get very very huge. Instead they use key files which contain key fields, offsets into the actual data file, and pointers to the next key field. This normally involves complex binary trees and structures.

Writing a small relational database program might be a good project for a 4th year college student (400 or 500 level college course).

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

What?!?!? Jesus is the reason Pilate and Herod existed? Absolutely illogical, my dear. That's like saying that oxygen exists simply because we breath it. It's proven that they both existed. They are in historical records. Facts prove you wrong here. Whether or not Jesus existed has

She was not saying Pilate and Herod did not exist -- of course they did. What she was saying was that Jueus existed just as much as Pilate and Herod did -- there are written records that all three existed. And we can take that a step further -- if anyone disputes the existance of Jesus then they must also disbelieve the existance of all dead people. Afterall, if you can't see them then they did not exist :mrgreen:

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

Vista and XP have different versions of DirectX so maybe that's the problem. You could try comiling on XP and see if it will run in Vista. There are a lot of programs that run in XP but not in Vista, and probably vice versa.

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

TCHAR is a macro that is defined to be char* if UNICODE is not defined, or wchar_t if UNICODE is defined. If you want to convert from char* to wchar_t* regardless of UNICODE definition then you can not use the TCHAR macro. one data type can not be converted to the other by simply typcasting -- you must use one of the convertion functions, such as this one.

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

just count the lines as they are read and stop when it has read the line you need. Toss all lines but the last one away.

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

Gah, c++.net, horrible. Much prefer pure c++.

I agree, but that doesn't help to solve the problem. I don't have that compiler so I can't help either. I think M$ rewrote all CLR libraries between .NET 2003 and 2005, so attempting to compile with 2005 if fruitless.

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

how was it initialized and allocated (new or malloc() ? Is list or str NULL pointers ? Hard to say what the problem is without more code.

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

I just use regsvr32.exe program in a command prompt window to register a DLL -- no difference between versions of MS-Windows.

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

You must write a separate function called isLeapYear that takes a year as a parameter and returns whether or not that year is a leap year. - not sure how
also not sure how to get it to print up to five leap years per line.

Looks like you have almost completed the assignment. To print 5 leap years per line I would add another counter in that loop to count the number of leap years printed on the line -- when the counter reaches 5 then print a "\n";

int counter = 0;
for(int i = x; i <= z; i++)
{
    if (isLeapYear(i))
    {
        cout << i << " ";
        if( ++counter == 5)
        {
            cout << "\n";
            counter = 0;
         }
     }
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just how long does it take your compiler to compile a small C program anyway? What version of MS-Windows or MS-DOS is running on your computer. How fast is the hard drive and RAM ? Have you run a virus scanner and a SpyWare scanner ? If your computer is an 80x88 1.4Mz CPU (yes I had one of those 15 years ago) then yes, you can read the novel War And Peace between compiles.