andor 25 Posting Whiz in Training

Hello

I'm working on an application.
I need as big arrays as possible. At home I work with linux there I can declare array as big as this: char buffer[1000000]. No probleme.

In work I'm working with boreland C++ 4.5 (WinXp) and I can't declare biger size of array as buffer[20000].
It tels me << constant is long << and << array size too large;

It is possible to change this? or Is there some reason to not declare bigger Arrays like this?

Please help...

I never worked with borland but probably U need to change the stack size in your compiler options. So go for help and find stack size. U can try also to declare the array as global becouse then its not using the stack.

andor 25 Posting Whiz in Training

I'm taking CSCI 230 and was able to get a triangle to print with the following code. I can't get anything to work for a circle or rectangle (similar in size). Can anyone help? Thanks.

#include <stdio.h>
int main()
{
int t;
int x = 0;
int y;
t = 0;
while ( t < 6 )
{
y = 0;
while ( y < t)
{
printf("* ");
y++;
}
if(x == r)
{
printf("\n");
x = t + 1;
}
t++;
}
return 0;
}

Use code tags and fix the code becouse it won't compile. r is undeclared

andor 25 Posting Whiz in Training

Use code tags and read this

andor 25 Posting Whiz in Training

Read this

Salem commented: Agreed - Salem +3
andor 25 Posting Whiz in Training

No it dose not exist. Replace it with

do
{
   /* your code going here */
} while(a<b);
andor 25 Posting Whiz in Training

You have included header.h twice (In both files). Use some sort code like of this (might be C++, sorry)

#ifndef HEADER
#define HEADER
#include "header.h"
#endif

But I dunno wether that is the real problem

Its better in *.h file to do the protection

/**********
* header.h file
***********/
#ifndef HEADER_H
#define HEADER_H
/**** some func declarations ***/
#endif /* HEADER_H */

then in c file.

andor 25 Posting Whiz in Training

Hm did U got corrupted code and your task is to fix it?
No?!?! Ok then just remove ; after while loop.

andor 25 Posting Whiz in Training

So if I understand corectly even you include your header files the compiler tells you that they are implicitly declared. That means that in first case they were also implicitly declared but the linker resolved the problems but with the second compiler the linker didn't resolved it. Always declare explicitly if U want to avoid these kind of problems.
Btw the getline is not C function and its not declared in stdio.h.

andor 25 Posting Whiz in Training

hi every one!! can anyone send me a sample program that creates a different beep sounds.. meaning by pressing diffrent letter, a diffrent tone sounds.. beep of diffrent frequency...

Against rules dude. Which language?

andor 25 Posting Whiz in Training

Convert cust_num to string for example with sprintf.

char buff[MAX];
sprintf(buff, "%d", cust_num);
fputs(buff, fpr);
/* and for fputc */
fputc(cust_num + '0', fpr); /* suposing that cust_num is less than 10 and smalles 0 */
andor 25 Posting Whiz in Training

HI, I have exe file writen in c++ or c and wanna decompile it to source code.
Is that possible? If it is, is there any decompilet that can do that?

thanks!

Then you must learn assembler. But why do U need it?

andor 25 Posting Whiz in Training

hi iface aproblem in c program
i want to write aprogram to read R={(1,2),(2,1),(3,3),......}
then covert it to matrix0/1
please help me quickly

You need to performulate. Don't understand. You need arrays of rows?

andor 25 Posting Whiz in Training

I will try to answer some of yout questions.

Is assembly worth learning it?

The answer is yes and no. Learn it but dont crack your head about it.

1. I hear a lot of people saying that the only people still writing assembly are some crazy old hackers that refuse to use anything else. Is that true?

No its not true. Ok old guys using them more than young ones, but not for hacking. For example for optimising, but not for PC but for embedded systems.

2. I hear also that anyone wanting/trying to make a real application in assembly (except device drivers) is a masochist. Like make a GUI in Windows or something. Is that true?

Yes he is masochist (this is only my opinion which can be false).

It has come to my attention, that there is no dedicated forum for Linux Assembly on the whole web! The only resources/discussions I have seen are a couple of blogs and some empty/deserted subforums in larger assembly forums.
What is the reason of this limited interest in Linux Assembly?

Once time I wanted to add tutorial for MIPS assembler, and I posted a thread to ask where can I do it. This answer I got. So now you know the answer for your question.

Does this mean that noone uses assembly on Linux?
Or does that mean that doing assembly on Linux is pretty much useless?

Skipping these questions becouse don't know the answer.

andor 25 Posting Whiz in Training

If I want to exit to Dos in a C program from a Switch statement, how do I do it?

Thanks

So no moderators on assembly forum? This should be moved to c/c++ forum. Ok I will tell you. Suposing that your switch statemant is in main function.

int main()
{
   /* declare someNum */
   /* assigning value to someNum */
   switch(someNum)
   {
   case something1:
      /* do stuff */
      break;
   case something2:
      /* do stuff */
      break;
   default:
      return 1; /* exiting from program */
      break; /* damn never be here */
   }
   /* here doing something what you tought to do */
   return 0;
}

If you creat project, creat console app. Hope I understood your problem.

andor 25 Posting Whiz in Training

Hi,
can any one tell me what size_t_count does, i couldnt get it .
thanks guyz !

fwrite(const void*_str,size_t_Size,size_t_count,file *_File);

It means how many of size_t_Size you want to write. fwrite(buff, sizeof(int), 4, someFile) means you want to write four ints to file.

andor 25 Posting Whiz in Training

U wrote this code and U have bracket problem :rolleyes: ? If U want to compile this code remove two brackets in front of while loop. Your problem not ends here. Read this. There are more problems but first do this.

andor 25 Posting Whiz in Training

Ok in subtotal function you are not adding the value of the fifth item.
Now if you can, try to avoid globals, use them only if you must . Read this link for string input (don't get me wrong your prog is working with scanf but read the link).
PS: I hope that you are not taxed like this :) .

andor 25 Posting Whiz in Training

Thanks mate...but i need the solution in c++...is it posible??...sory for not specifying this at the start

Well this code is more C++ than C becouse in C you dont have string, only if you defined it explicitly as struct

andor 25 Posting Whiz in Training

You need to declare an array. For example int array[MAX_ELEM] . You must define MEX_ELEM (look on google whats macroes in C if U don't know). In a loop you must enter their elements. To pass the array size you can do like this sizeof(array)/sizeof(int) In bigger function you need to loop throught an array and find out the max value, for example

int max =0;
// for loop goes here
if (array[i] > max)
   max = array[i];
//end foor loop
return max;

PS: Don't post the same question twice ;)

andor 25 Posting Whiz in Training

Dude just post your error messages. I can't follow U

andor 25 Posting Whiz in Training

i is not defined in quicksort. I think that the problem is in quicksort func.

andor 25 Posting Whiz in Training

If theres no error mesages than the prog created the file. Put getchar() at the end of the program just to be shore that U did not missed the err message.

andor 25 Posting Whiz in Training

hello modt2.txt is not created...:sad:

The only diffrence is the while loop and the declaration of spaceOcured. There is no sense that mod2 is not created. Create a new dir and copy the c file and the modt.txt. Try again. It should create the file modt2.txt. Do you heve this error message error:unable to open the filed ? If U still have problem comment the while loop and leave only the fopen functions and see the result.

andor 25 Posting Whiz in Training

Hm are you shore?

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

void copyf(char *fname1, char *fname2){
   FILE *fp1,*fp2;
   int x;
   char spaceOcured = 0;

   if (((fp1=fopen(fname1,"r"))==NULL)||((fp2=fopen(fname2,"w"))==NULL)){
      printf("error:unable to open the filed\n");
      exit(1);
   }
   while((x=getc(fp1))!=EOF){
      if ((unsigned char) x != ' ' || spaceOcured != 1)
         putc(x,fp2);
      if ((unsigned char) x == ' '){
         spaceOcured = 1;
      }
      else{
         spaceOcured = 0;
      }
   }
    
   fclose(fp1);
   fclose(fp1);
}

int main(){

   copyf("modt.txt","modt2.txt");
 
 return 0;
}
andor 25 Posting Whiz in Training

you need ; after b++

andor 25 Posting Whiz in Training
while((x=getc(fp1))!=EOF){
      if ((unsigned char) x != ' ' || spaceOcured != 1)
         putc(x,fp2);
      if ((unsigned char) x == ' '){
         spaceOcured = 1;
      }
      else{
         spaceOcured = 0;
      }
   }

Of course you must to define spaceOcured at the begining of copyf function, for example to char and intialise it to zero.

andor 25 Posting Whiz in Training

How would you make the program pause for a certain amount of time? I can't just tell it to do some trivial task over and over for so many loops, because the compiler seems to know its trivial and cuts it out. There's gotta be a simpler way anyway.

Try to use sleep or usleep. I think that they are not standard functions but U can try. Use these func without including extra headers. The compiler will tell you that they are implicit declared. If they exist the linker will resolve this.
First function takes amount of seconds so for example sleep(1) will pause your program for one second, and the usleep uses microsecond usleep(1000000) will pause the prog for one second.

andor 25 Posting Whiz in Training

don't understand your problem. In modt.txt you have Have a nice day and in modt2.txt I also have the same string.
>i want to save it to the 2nd file without double space
This part I don't understand. Where you have double space? In 2nd file?

andor 25 Posting Whiz in Training

Use code tags. C is case sensitive so if you declare b than you cant use B. Compile the code and fix the syntax errors.

andor 25 Posting Whiz in Training
andor 25 Posting Whiz in Training

Beatuify all your posts by code tags

andor 25 Posting Whiz in Training

>I need help to either provide the C++ codes
This is against the forum rules.
>or point me the proper link to find the Euler cycle
Did you try with google?

andor 25 Posting Whiz in Training

Do you have the adequate library for this code?

andor 25 Posting Whiz in Training

is possible to make .exe files with gcc (for win)

Yes it's posible with cygwin. Did you fix the sin problem? Try to add when U compile -lm. gcc example.c -o example -Wall -lm -W -pedantic -ansi

andor 25 Posting Whiz in Training

Use code tags and don't use void main (read this)

andor 25 Posting Whiz in Training

Sorry, What forum should i be posting in?.... i want to write the program in C++ and therefore thought i should post it in the C++ forum... Please advise!!

Just to clarify, i don't want to download a file recovery program... i'm going to write a file recovery program.....and wondered if anybody here and also done this?

No you posted to the right forum just ~s.o.s~ didn't understand that you want to write the program in c++ and not to recover deleted file

andor 25 Posting Whiz in Training

Change the constructor to

rectangle()
    {
      length = 1;
      width = 1;
    }            //constructor sets length and width defaults to 1

or

rectangle():length(1), width(1) {}

Compile and run

hoosier23 commented: very thorough +1
andor 25 Posting Whiz in Training

i believe you can set the data type to zero in this instance, unless my book is wrong...

they have..


class Time {
public:
Time(int = 0, int = 0, int = 0); //default constructor
private:
int hour;
int minute;
int second;
};


//i am also not using a get or set function from a library... this is just my variable name

Hm never seen that (probably becouse I'm not c++ programmer). But the book never lies. Make a test just leave the construtor and what will the copiler tell U

andor 25 Posting Whiz in Training

Yuo should run throught tutorial. You should know the diffrence from set and get. For example

float getLength(float)
    {
        float Len;
        cout << "Enter the length: ";
        cin >> Len;
        cout << endl;
        return Len;
    }

you need

float getLength(void)
    {
        
        return length;
    }

For set func

void setLength(float someLen)
{
   length = someLen;
}

The constructor is wrong also you cant assign values to types.

rectangle(float=1.0, float=1.0);

instead

rectangle(float Len, float Width)
{
   length = Len;
   width = Width;
}
andor 25 Posting Whiz in Training

With which part do you have problem? Formula for conversion or programming issue? For formulas, read this. For declaring char and inputting you got the answer from second post of this thread

andor 25 Posting Whiz in Training

Try to write it on your own and when you have some code than we'll help you about the optimisation

andor 25 Posting Whiz in Training

And the question is?

andor 25 Posting Whiz in Training

Right now i am testing for ch, and before pch tests for ; ch is null
so the program should end there itself when ch is null, why would it continue till pch??

The point is that ch is not NULL. Check the debug printf in my post

andor 25 Posting Whiz in Training

The seg fault is becouse if you dont have ';' then pch is NULL. So seg fault will happen only if you dont have ';' in the input string. You need to change the logic

#include<stdio.h>
#include <string.h>
#include<stdlib.h>
void function(char *);
int j;
struct test
{
   char member1[20];
   char member2[20];
};
struct test *tr;
int main()
{
   char str[100], *ptr;
   printf("enter the string: ");
   /* scanf("%s",&str); */
   fgets(str, sizeof(str), stdin);
   if((ptr = strchr(str, '\n')) != NULL)
      *ptr = '\0';
   tr=(struct test *)malloc( sizeof (struct test)*100);
   function(str);
   free(tr);
   return 0;
}
void function(char * str)
{
   long int i,index,k;
   char str1[100],*ch = NULL,*pch = NULL;
   j=0;
   tr->member1[0] = '\0';
   tr->member2[0] = '\0';
   
   ch=strtok(str, ":");
   printf("*ch = %c\n", *ch); /* debug print */
   if (ch==NULL)
      exit(0);
   while(ch!=NULL)
   {
      pch=strstr(ch,";");
      if (pch == NULL)
      {
         ch=strtok(NULL,":");
         continue;
      }
      printf("*pch = %c\n", *pch); /* debug print */
      i=pch-ch;
      printf("i = %ld\n", i);
      strncpy(tr[j].member1,ch,i);
      strcpy(tr[j].member2,pch+1);
      j++;
      ch=strtok(NULL,":");
   }
   for(k=0;k<j;k++)
   {
      printf("\n%s",tr[k].member1);
      printf("\n%s",tr[k].member2);
   }
}

Run this

andor 25 Posting Whiz in Training

I have #include<iomanip> header also and it's still not working.I am getting 2 dec places but it's .00 Why is that?Please help.
here is the code
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;


also this code is not working ,when I use the [ ] at the end,I am getting an error so I am using () instead but the calculation is incorrect.Please help

float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);

If you want help you need to post the whole code. Read this

andor 25 Posting Whiz in Training

>error C2061: syntax error : identifier 'scanf'
it means you need ( before scanf.
>I still have to figure out why my average value is coming out wrong.
Did U read my post?
>What would be the best way to figure out the average?
Accumulating the miles / gallons and then dividing with number which represent how many times miles / gallons were calculated.

// dont forget to initialise totalTank to zero
while(numberOfTime)
{
   tank = miles / gallon;
   totalTank += tank;
}
avarageTank = totalTank / numberOfTime;
andor 25 Posting Whiz in Training

it didn't work . i think the segmentation error is because of some logical error not because of scanf(), gets() problem

Thats why we insist to post the code or if you cant, then U need to reconstruct the problem in smaler code. The post I posted don't give seg error, if U don't belive me compile and run the code which I posted.

andor 25 Posting Whiz in Training

Okay, so what libraries are getch() and kbhit() included in? (I think I might test this one out, after I reformat my computer...)

In conio.h but this is not standard so there are posibility that you don't have this library.

andor 25 Posting Whiz in Training

You are not calculating the total gallons after first gallon input before while, and after finishing the prog you are substacting from total gallons -1.

andor 25 Posting Whiz in Training

Did you tried cin.ignore after cin.get(ifname, 150); ?