ssharish2005 62 Posting Whiz in Training

I HAVE A VERY PECULIAR PROBLEM,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


THE PROGRAMS I COMPILE SHUT DOWN AFTER COMPILING ONCE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

FOR EG-
I CREATED THIS PROGRAM FOR GETTING THE ASCII CODES OF AN ALPHABET ,,,,,,,,,,,,,,,,,,
AFTER I WROTE THE ALPHABET IN DOS IT DISPLAYED ITS VALUE AND SHUTDOWN,,,,,,,,,,,,,,,,
HOW CAN I ALTER MY PROGRAM TO TAKE IN AS MANY VALUES AS I WANT????????????????????????????????

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


main()
{
char a;
clrscr();
printf("enter any character\n");
scanf("%c",&a);
printf("the ascii code of %c is %d",a,a);
getch();
}

THANK YOU,,,,,,,,,,,,,,,,,,,,,

Well, that because you used the scanf function to read the value. The quick solution for this is to place two getch or getchar()! Or you will have to call the following function just above the getch() function or everything you read a char you will have to call this function before you read. That makes sure that the input buffer is clear and program won't shutdown!

void clear_buffer( void )
{
     int ch;
     while( ( ch = getchar() ) != '\n' && ch != EOF );
}

-ssharish

ssharish2005 62 Posting Whiz in Training

>how do i save the c programs i compiled on borland c++ on the dekstop???????????????????????
Well, when you compile the C code you would the binary or the .exe file out of it. Unless you have any errors. Assuming that your program compiled with no warning or errors, the .exe file should be in you local working directory. If you want to save the binary of it on the desktop then i guess you will have to look at the compile command line options and look for an flag output.

Just made a quick search, it’s the -n flag that you would have to use. That is

bcc<x> -n <output dir path> <source file>

<output dir path> Please see AD post.

-ssharish

ssharish2005 62 Posting Whiz in Training

Use sprintf function to convert int to string. Thats the more portable way of doing it. Since itoa is not portable!

char *cvtInt( char *str, int num)
{
    sprintf( str, "%d", num );
}

ssharish

ssharish2005 62 Posting Whiz in Training

Isn't negative factorial kind of wrong altogether?

YES it is :) Perhaps the OP should check the value of n, before sending the value to the fact function.

print "Value for n ?"
   read n

if( n >= 1 )
   print fact( n )
else
  Error

ssharish

ssharish2005 62 Posting Whiz in Training

how could I add something to the function so it calculates when and if n is negative

Well, you got to be pretty careful on what your placing in the recursive function. The function is built to find the factorial for a given number. Tell me what are you trying to achieve.

Why do you want to check for n is negative??

if( n < 0 ) {   ...   }

This should check for the negative function. You could perhaps replace the statment in your fact function and see what output you get. I would guess not the right answer your looking for!

ssharish

ssharish2005 62 Posting Whiz in Training

Well there are few thing which you need to consider. First of all the function name is not write. In you code you have declared a function prototype clearly, but why dosn;t that reflect in your function definiation.

Your function name is return1 which should be return1. And then within the function your should check for n <= 0 not 1 or n == 0 . And also if thats true you should return 1 not return1 . Give a space between return and 1.

ssharish

ssharish2005 62 Posting Whiz in Training
int return1 (int n);

Why is that semicolon there??? Delete that! Syntax error

ssharish

ssharish2005 62 Posting Whiz in Training

Perhaps you should make an effort to search on the form. There might be like tons of results on this issues. But here is the pesudo code.

<return type of int> function name FACT ( taking int as an argument )
{
   if n equals to zero
      return one;
   else
       return n multiple FACT ( n minus one );
}

NB: Learn to start using code tags!

ssharish

ssharish2005 62 Posting Whiz in Training

You dont have to have such a huge list if and else to do this. You to reduce that to just few lines of code. Looks the my version of convert function.

int convert( char *str, int *number )
{
     int i;
     
     for( i=0; str[i] != '\0'; i++ )
         if( isalpha( str[i] ) )
             number[i] = (str[i] - '0') - 7;
         else
             number[i] = (str[i] - '0');
         
     return i;
}
/* my output
my input - char str[] = "123456789ABCDEF";

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
*/

ssharish

ssharish2005 62 Posting Whiz in Training
scanf("%d", &miles);

You need to read double here. But you are reading integer. Or at least change the type of miles here to integer. You might actually expect some meaningful result.

And you have an infinite loop in your code. Your program will keep requesting for miles every time. It donst even come of loop. Since you read gall ,just once and miles every time. Perhaps you should change the while condition to check miles != -1 .

ssharish

ssharish2005 62 Posting Whiz in Training

Well, i could see some other problem as well now with that code. Can you please post the error message please

ssharish

ssharish2005 62 Posting Whiz in Training

#define GCD(); Take of that semicolon from that statment. Macros donst need a semicolon. If your marco definiation are like too big then you might use a '\' to speak it up and concatenate.

But for you just the semicolon off.

ssharish

ssharish2005 62 Posting Whiz in Training

pLike, you should really consider looking at on how to indentent you code first. Well the error message you get there is basiclly specifying that GetInteger cannot be assigned to the interger. It donst know what the RHS is? Seems to me like it is function or is it macro if there was no brackets ????

#include <stdio.h>

int main()
{
    int a, b, c, x, y, z;

    printf("Enter A: ");
    a = GetInteger();

    printf("Enter B: ");
    b = GetInteger();

    printf("Enter c: ");
    c = GetInteger();

    z = ( b * b - 4 * a * c );
    x = ( ( -b - z ) / ( 2 * a ) );
    y = ( ( -b + z ) / ( 2 * a ) );

    if ( x == y )
    	printf("There is one solution: %d", x);
    else if ( x != y )
    	printf("There are two solutions: %d and %d", x, y);
    else
    	printf("There are no solutions");

    system("pause");
    return 0;
}

And the in the if statment, there two two equals opeator not the assignment operator if ( x == y ) ssharish

ssharish2005 62 Posting Whiz in Training

It has nothing to do with IPC.
Just use process inheritance (CP)

He did ask, on how to create process and stuff. The link should give him an idea. Perhaps Salem's solution seems the best!

ssharish

ssharish2005 62 Posting Whiz in Training

>dry runs
True, should have notices that key work.

ssharish

ssharish2005 62 Posting Whiz in Training

Well, the pesudo code should be converted to a code and then try with some test input.

Well, YES, you cant just compile a pesudo code. So on what language are you suppose to implement the pesudo code. There are few tools which converts the pesudo code to code. But, you will have to learn the pesudo code standard and which that specific tools can understand.

Some hint on the looks like Yacc, Yapp. Wel those tools are used for compiler design but you cant use it for your application. They understand a notation called BNF.

That should give an idea. YOU WILL HAVE TO IMPLEMENT THE CODE TO TEST IT.

ssharish

ssharish2005 62 Posting Whiz in Training

Ohh man, you need to properly indentent your code. It so difficult to go through with that code.

Identent your code, you might except more help.

And what is '#' char in each line? Dosnt look good!

ssharish

ssharish2005 62 Posting Whiz in Training

You perhaps have a look into a concept called Inter Process Communication (IPC) Have a look at the following tutorial.

You create a new process by call a function called fork() and you start a new program within that process using a exec family functions.

Have a look at this link

http://www.ecst.csuchico.edu/~beej/guide/ipc/

ssharish

ssharish2005 62 Posting Whiz in Training

Well, that gonna be difficult using the system function, since the function doesn’t return anything expect the status i.e 0 or 1.

What you could do is pipe the output to a file and access that file to get the output of that program.

Or you will have to fork a new process and run the program in that new process and pipe or redirect the output of the child process as an input to the parent process.

ssharish

ssharish2005 62 Posting Whiz in Training

Perhaps, you should have posted this question on a C++ form :-/.

And few things which I saw in your code, which you might have to consider to correcting

#include <stdio.h>
to 
#include <cstdio>

And main should return a value. Well, it’s already if you don’t specify it as well, under C99 it automatically assumes to be return 0. But it is always a good practice to place them explicitly.

system("PAUSE");

Using system function is not very portable. You might have to consider using some different function. Have a look this thread
http://www.daniweb.com/forums/thread90228.html

NOTE: I still wonder why do you consider including

#include <iostream>
and
using namespace std;

You are just mixing up languages. Did anybody guide you to do that??

ssharish

ssharish2005 62 Posting Whiz in Training

I don’t have much to say, b’cos most of the clues on why this happened has been already pointed out. But the main cause for this problem is when you run the code once and then try running it once again or compile or rebuilt it. You might have to make sure that the program has exited properly. Use the processor explores windows to check if the process is still running.

You might be doing something wrong in your code may be. See if you your program exits properly. Salems link for processor explore is a very good tools to check to make sure if there are any other process having of your code file etc.

On my research it seems that, this is a known issue which the VS team is already aware of. Got this information from the following link? But still make sure that by disabling all antivirus software and run it again.

http://connect.live.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=292259

You might find this link useful as well.

http://support.microsoft.com/kb/308358

ssharish

ssharish2005 62 Posting Whiz in Training

Well, it does make any difference in assiging the a string to a char pointer. What I really wonder is how is that killing your processor. Is there any loops which goes to an infinite loop? Or there may be some problems with the implemenation of that function may be. What does your application do?

ssharish

ssharish2005 62 Posting Whiz in Training

It would have been more nice, to see what problem you had. May be we could learn more from that as well. Please do post the problem and the solution you came your problem. You might get some more help and perhaps some feedback on your solution.

NOTE: If you started this started them you could mark this thread as solved, if you found the solution. ;)

ssharish

ssharish2005 62 Posting Whiz in Training

YES, it does say to prototype there

get_current_dir_name(), which is only prototyped if _GNU_SOURCE is defined

http://linux.die.net/man/3/get_current_dir_name

ssharish

ssharish2005 62 Posting Whiz in Training

Jobs you are in a right track. Thats right When do this

void foo(FILE *fp);

in main
foo (fp);

When you call foo the address of the file pointer will be copies and sent to the foo function. If you wanted to send it through reference then you will have to do something like this

void foo(FILE **);

in mian
foo(*fp);

But the first method would do what you want.

ssharish

ssharish2005 62 Posting Whiz in Training

Well, C supports in multi threading. But before i can say anything about light weight process. I should ask you which OS and compiler are you using.

If you are on Linux, you should looking at something called pthread library.

ssharish

ssharish2005 62 Posting Whiz in Training

i cant unzip it on my machine, just use the windows compress utility feature. Or perhaps just post the make file contents

ssharish

ssharish2005 62 Posting Whiz in Training

Why do u want to place that in a 3 byte stream when that can fit in 2 byte stream.

ssharish2005

ssharish2005 62 Posting Whiz in Training

I am seeing this as a second post now. :)

ssharish2005