csurfer 422 Posting Pro

I think the conversation is loosing track. You want to write a C program to write main function,take input in array and then sort it through some sorting algorithm and then run search through your assembly program right? Concentrate on that.Do this first:

1)Writing a main program and taking inputs into array should be simple as it is very much similar to JAVA programming the same thing.Do it first.

2)You will get all the help needed for sorting algorithms form this community threads and also the link
http://en.wikipedia.org/wiki/Sorting_algorithm

3)If you want it still simplified here you get algorithm and modules to write bubble sort and also simulated explaination.
http://www.cs.princeton.edu/~ah/alg_anim/gawain-4.0/BubbleSort.html

4)After this concentrate on making it search for the user input in the array through your assembly code.

Don't loose your way.Concentrate on what path to take to make compiler do your work.Then you can code anything.

csurfer 422 Posting Pro

We know #define statements are executed before the program is compiled (preprocessor directives) and so the characters used should have no other meaning (say keywords),but still the following statement is not possible and is erroneous why ?

#define int float

How many passes would the preprocessor directives run for as for the following type of statements,more than one pass would be required...

#define a b
#define b c
#define c a

Sort of confused right now...so thought of asking you guys...!!! Thanks in advance !!!

csurfer 422 Posting Pro

What good would strstr do after you have tokenized the string???

Declare a string array and an integer array of some respectable size.

Tokenize the string and assign every string formed to the indexes of string array.Now use the string array indexes and strcmp to find the repetition of a particular string and store the number of repetitions in the integer array and initialize all the repeated strings to null every time you use strcmp.

csurfer 422 Posting Pro

Here are some points which might help...

1)The program is perfectly alright and is running without any changes in it (In windows).

2)While running it through command prompt or in a shell it might cause some problems(may be i dont know) because of your argc and argv (why not just say main(void) as you are not taking any input from command line.)

3)The formula for s is not for all lengths which come to your mind.It should form a triangle, only then can you expect an answer (Keep in mind the rule "SUM OF TWO SIDE OF A TRIANGLE SHOULD ALWAYS BE GREATER THAN THE THIRD SIDE"...it applies to all sides...)

csurfer 422 Posting Pro

whether there is c program implimentation forthe stable marriage problem? How can I extend this problem in a real life situation?

Would you please state the problem please...

csurfer 422 Posting Pro

Also i would like to know, In Unix what are the cases in which C program encounters a segmentation fault/core dump?

I didn't get your earlier question but segmentation fault in UNIX mainly appears in cases of illegal memory access.I mean problem with your pointers.

csurfer 422 Posting Pro

I really think you need to relax your brain because you are going wrong again in this :

do{
printf("Would you like to place another order? (Y/N)");
scanf("%c",&end);
end = toupper(end);
}while (end != 'Y' && end != 'N');

Here the do while loop only works if you press in some garbage value or character apart from "y" and "n".That is not what you want.Just change it to

while(end!='N')

I don't see any problem with the toupper call. Just the above change is enough and I haven't gone through other parts of your program.

csurfer 422 Posting Pro

Thanks for helping me guyz, my second problem is about the character "end".

i used toupper but it's not working..

do{
	printf("Would you like to place another order?  (Y/N)");
	scanf("%c",&end);

	end = toupper(end);

	}while (end != 'Y' || end != 'N');

T_T

while (end != 'Y' || end != 'N');

This statement is a complete nonsense...If end is equal to Y you need to loop again right? This thing doesn't do anything...
Atleast do this :

while (end == 'Y' || end != 'N');

or even this:

while (end == 'Y' );

And it involves the header file "ctype.h"

csurfer 422 Posting Pro

Here you are declaring the array within the function and then returning it to the main. This kind of things always do create problems as the local variable is tried to destroy as soon as the control comes out of that function.

So its better always to create the array in main and then pass it to the function to manipulate it.So that you will be sure that the array does have an existence in main.

csurfer 422 Posting Pro

>theMenu[0].menuItem[LENGTH]=" [1] Chicken A";
That won't work either. You'll have to strcpy the strings into the character arrays, or point each node of menuItem to a string literal and then make menuItem a const char pointer (to make sure that you don't accidentally try to modify the string literal).

Ya a mistake on my part sorry I got it confused with

char arr[30]="Hello I am .....";

But that cannot be done on the later part I mean after initialization so best method is as you suggested "strcpy". This is the reason I love this forum.I get a chance to learn a new thing and also learn from my mistakes every now and then.Every one please note "A small mistake on one topic done by you will make this forum teach you two topics.Thanks Daniweb!!!"

csurfer 422 Posting Pro

Try adding your TC path to the "path" ENVIRONMENTAL VARIABLE in system properties.More info given http://www.daniweb.com/forums/thread175434.html look at this thread.

csurfer 422 Posting Pro

Make these changes in getData function:

int getData(int);

change this to

int getData();

-------------------------------------------------

choice = getData(int);

change this to

choice = getData();

-------------------------------------------------

int getData(int z)
{
	z=0;

change this to

int getData()
{
	int z=0;

----------------------------------------------------------------------------
----------------------------------------------------------------------------
You cannot do this in menu function:

strcpy(theMenu[y].menuItem[LENGTH],{	" [1]  Chicken A",
					" [2]  Chicken B",
					" [3]  Chicken C",
					" [4]  Chicken D",
					" [5]  Chicken E",

You need to do it separate initialization only for both the arrays as:

theMenu[0].menuItem[LENGTH]=" [1]  Chicken A";
theMenu[1].menuItem[LENGTH]=" [2]  Chicken B";
theMenu[2].menuItem[LENGTH]=" [3]  Chicken C";
theMenu[3].menuItem[LENGTH]=" [4]  Chicken D";
theMenu[4].menuItem[LENGTH]=" [5]  Chicken E";
//continues
csurfer 422 Posting Pro

plz help me to add two matrices using pointers..

1>Take two integer matrices say a[20],b[20],and a result matrix c[20],and two integer pointers pa and pb.

2>Assign the start address of arrays to these pointers.

3>Now if p points to a[0] then p+1 points to a[1] and you can even access it as *(p+1) which is equal to a[1].

4>By the above mentioned process go on adding two matrices by using *(p+i) and store it in c.

csurfer 422 Posting Pro

>Naure

I used devc++ with the proposed changes but it has some problem with the recognition of timeval struct itself,and also wit the usage of tv.tv_sec.Any suggestions with regard to usage and also the good compiler to use???

csurfer 422 Posting Pro

That thing should work.It surely works for me.May be its due to your compiler.Some compilers like TC brands don't support usage of system calls so easily.I use devc++ compiler and it works fine with that and also gcc compilers too.

csurfer 422 Posting Pro

Hey assuming you want to sort your strings in order "smaller to larger" as you have been using the word "min" many times these are the things you need to do.

1>Correct every mistake nucleon has already stated.

2>Your selection sort function is a completely mess. You are comparing text and text[i+1] and setting value of j to min which doesn't make any sense.It looks like this with errors marked:

void selectionSort(char text[NUM][LEN]) {
int i, j;
int min;
for(i = 0; i < NUM -1; i++)
{
min = i;
for(j = i + 1; j < NUM; j++)
{
CompareStrings(text[i], text[i+1]); 
/*Error : You need to compare text[min] and text[j] */
if(CompareStrings(text[i], text[i+1]) == -1); 
/* Why extra comparison mentioned above??? How ever this thing isn't doing anything*/ 
{min = j;} /*j isn't into picture at all*/
}
SwapStrings(text[i], text[i+1]); 
/* why running a loop with j when u r just doing this?*/
}
return;
}

It should be as this :

void selectionSort(char text[NUM][LEN]) 
{
int i, j;
int min;
for(i = 0; i < NUM -1; i++)
{
     min = i;
     for(j = i + 1; j < NUM; j++)
     {
          if(CompareStrings(text[min],text[j]) == 1) min = j;
     }
     SwapStrings(text[i],text[min]);
}
return;
}

These are the errors i saw when I read the program once.I haven't compiled it.Try this once and post your further queries.

csurfer 422 Posting Pro

Assuming that you want to print out or store the 8bit hex values of each character of the input string I am giving these guidelines.

Firstly take the input into an array by name str[30] may be.
Let the final array be:
unsigned char foo[30][30];

Now convert every one of the characters in the input string into their hex values and store it in an array of array of character strings as :

for(i=0;i<strlen(str);i++)
{
        // Alteration
        foo[i][0]='0';
        foo[i][1]='x';
        itoa(str[i],&foo[i][2],16);
}

If you want three to be treated as 3 and not '3' then you can alter the code by placing this statement in place of "//Alteration" in for loop:

if(isdigit(str[i])) str[i]=str[i]-'0';

But ya as nucleon said every number will be stored as a hex constant itself this would be one of the process to store those hex values somewhere else in the format:
0x<8bit hex value>

Hope this helps !!! :)

csurfer 422 Posting Pro

@csurfer
i thought that you cannot read a string like scanf ("%s", stu_name[j]); if you defined stu_name like char stu_name[MAX_LENGTH];

death_oclock has already answered your point I suppose.Right?
usage:

char stu_name[30];
scanf("%s",stu_name[<some number>]);

is definitely wrong as you need to pass a char pointer to the start of an allocated memory to scanf to read a string into it.( As allocating a char array and passing the array name )

But the usage here is :

char stu_name[30][30]; // An example
for(i=0;i<30;i++)
                    scanf("%s",stu_name[i]);

which is equal to passing &stu_name[0] which is perfectly right so that you can store "i" number of names where every ith name is in array stu_name[30].Now got the point?

csurfer 422 Posting Pro

I couldn't understand step-2...ie,making finale string.Suppose I have to open the file located @ d:\hello.txt,My command line system("d:\hello.txt ") doesn't work at all.What should i have to do for that task.

Well what Aia told is right C is not a good compiler and the method suggested by me is not too good but it will work in a way.

Well what i meant was that system() is the call given to run any command which you would have run in command prompt so in command prompt if u needed to open a file at d:\hello.txt you would give

>edit d:\hello.txt [ENTER]

now this is the string you need to send to system to execute that dos command through C file as:

system("edit d:\hello.txt");

I hope you got it now.

csurfer 422 Posting Pro

Your program runs fine. Just make this small change and it will run.

In your program it is:

for(k=1;k<=3;k++){
for(j=1;j<=5;j++){
for(i=1;i<=j;i++){

Change this thing as :

for(k=1;k<=3;k++){
for(j=1;j<=5;j+=2){   //Only change required...
for(i=1;i<=j;i++){

In your code once a loop is finished the next set of runs for the innermost first loop is equal to the previous loop run value of innermost second loop. Due to this it was printing same number of '@' and '*'.By this small change it will run fine.

csurfer 422 Posting Pro

Whats the problem???Take a file pointer as

FILE *fp;
fp=fopen("<path>","<permission>");
//error check

csurfer 422 Posting Pro

Hey death_oclock is right. Not the other guy.Your question says details about many students so it should be of format:

student_name[<number of students>][<max length you would expect of a name>];

And ya as per my suggestion you sincerely need to optimize your code.There are many redundant and waste lines too.Ex:

printf("\n");
printf("\t");
printf("%s\t",stu_name[j]);

Why are you simply increasing the length of the code and also reducing its readability???You could also write this as:

printf("\n\t%s\t",stu_name[j]);

Also right??? Of course this is not redundant but first two lines needn't be separate lines.You got to look through and optimize your code.

csurfer 422 Posting Pro

how to write a program for raising a number to a power(integer only)
(e.g 2^2=4 ; 3^3=27 etc)
without using a precompiled C function(ie pow()). but only used addition, substraction, while loops,if statement and/or for loop.

You intend to do it without inbuilt library functions like pow() right ? Do it with recursive call of a function as:

int power( int b , int p)
{
if( p > 1 )
               return b * power( b , p-1 );
else
               return b;
}

where b and p would take the format in library function pow as pow(b,p).Just call the above shown function in main passing the two numbers as arguments.Your work is done.
There are many other ways of doing this.But its just left to your interest.If you really want to learn programming in C then try in ow many ways can you write the same program(using different logic) and to what extent you can simplify.

csurfer 422 Posting Pro

>BimanD

Did you even read what the question posed was...? And what others have replied to it...?

csurfer 422 Posting Pro

Well this is not very efficient method but as you are using nearly 80 arrays it might come handy.

Just do this :

for(i=0;i<80;i++)
     for(j=0;j<80;j++)
          Temp_array[j] = Array[j][i];

In the above mentioned way you will move every element in first row to temporary array.And now apply some method on this temp array to find out the max value and move it to

Result_array[j] = maxof( Temp_Array[] );

Thats it simple to use but not highly efficient.

csurfer 422 Posting Pro

>Well I couldn't really make out if you people were against
>usage of system library function here in this context.
By my reading, death_oclock isn't sure, and ArkM hasn't stated a preference.

>If yes could you state the reason...?
In this case, system is still risky, but no more risky than ShellExecute as they both have the same vulnerability: unless you're careful about the path you pass, a malicious program can be run in place of the one you expected.

Path is still a user input right ? As both system and ShellExecute have same problems on the system side execution,its just the path which determines whether it would suit this application or not.
So once we are sure that the path given by user is right the system(<path>) should not create any problem.Isn't it Naure?

csurfer 422 Posting Pro

Thanks for you help. I have figured out what I am doing wrong. For future reference though, is it possible to declare an array of strings? Isn't that effectively an array of character arrays?

You are exactly right . Array of strings is effectively an array of character arrays. As string is nothing but a character array.

csurfer 422 Posting Pro

>Csurfer, I've also tried out setting system variables as you said.. there were 2 system variables with names path (not PATH unless ur suggestion wasn't case-sensitive) and PATHEXT.. i tried indepepndently with each of them.. i wrote ;C\TC\TC.EXE(tell me if nething's wrong with it) but to no avail

Hey its just the path variable ( Path ) ok and whenever you are setting a path you don't include exe files to it . You just need to include C:\TC\BIN;C:\TC\LIB;C:\TC\BGI or in total as C:\TC ok .
The syntax of the path is also wrong and also the object you choose to include in the path.

csurfer 422 Posting Pro

>Arkm
>death_oclock
Well I couldn't really make out if you people were against usage of system library function here in this context.If yes could you state the reason...?

csurfer 422 Posting Pro

I want to write a program that can run a file in my hard disk.For example,a test.bmp file is there in location D:\home\test.bmp,that program should open(like double clicking on it ) that file (test.bmp) and i can view the image contained in the file.

For bitmap images (or images in particular) its a bit lengthy process(which I sadly don't know myself).I will just tell you the process to open any file for example a text file in particular.

Steps:
1>Make your code take the path of the file needed to be opened either through command line as argv or through scanf in the form of a string.
2>Combine this path taken from the user with other parts of a command like edit (edit <path of file >) to form the final string.
3>Pass this string as system call by the usage of function system
as

system("<final string>");
csurfer 422 Posting Pro

For pointer concept you look at the post by Naure I am just throwing some light on similarities between variable increment and pointer increment. (Thought that would help you link these two things and understand better.)

1)
variable + 1 = value of variable + 1
pointer + 1 = address pointed to by pointer + sizeof(pointer)

2)
variable++ = get value of variable , add one to it , store this value back into variable
pointer++ = get address pointed to by pointer , add sizeof(pointer) to it , make pointer point to this address

3)
variable + n (where n is any number )
value of variable + n

pointer + n (where n is any number )
address pointed to by pointer + n * sizeof(pointer)

4)
variable1 - variable2 = difference in their arithmetic value

pointer1 - pointer2 = difference in number of adresses
(they should be pointers to same type of variables as against the case in variable subtraction)

5)
Addition of pointers is not feasible but all addition of numeric constants to numbers can also be seen with subtraction of numeric numbers which act in reverse way.

6)
Multiplication division and all cannot be applied to pointers.

I hope this was of some help...

csurfer 422 Posting Pro

>Naure

How about using this assuming the numbers passed as strings are within the integer range...

if ( argc >= 3 ) {
num1=atoi(argv[1]);
num2=atoi(argv[2]);
printf ( "%d\n%d\n", num1, num2 );
}

Or if the coder is sure to get only singe digit numbers he/she can just use "Number" - 48 which would be faster than any of the above mentioned functions right?

csurfer 422 Posting Pro

death_oclock has already solved your problem.But what is your objective behind reversing of the numbers??? We could help you better if you could state that...

csurfer 422 Posting Pro

I have a sequence of 5 numbers. I want to write it in reverse order. Could you please help me that what will be the algorithm?

This is different from the question dealt in this thread so start a new one...

csurfer 422 Posting Pro

Hey there are few errors which you can work on:

1)

void chkEClass(.........................)
{
}

Has an error in first line as:

void chkEClass( , , , ,char firstname[],char lastname[])

this should be

void chkEClass( , , , ,char firstname[][LENGTH],char lastname[][LENGTH])

2)There exists an error in the looping concept while taking the input which exits the program even when the user hasn't finished his choices.

Go on through the code stage by stage as though you are compiling it you will find out the errors more clearly.

bemo55 commented: You were helpful. All it took was for me to take take to stop and look at my code line by line +1
csurfer 422 Posting Pro

>gets(char);
FYI, booze in fact does not improve your ability to write code. You'd have to be quite confused to write char when you meant firstname, and any experienced C programmer would have to be drunk to use gets.

Ya that was firstname. Sorry mis-representation. Call it a "Slip of keys". ;)

csurfer 422 Posting Pro

Hey its simple you just need to do the same working as you would do on a paper. Take the fraction as a string and break it into tokens with delimiter as "/" . Now you get the numbers as characters. Just convert them into integers and use them in the same way as you would use them on paper.

csurfer 422 Posting Pro

I have a project for school that i am working on, and i cant figure out how to store names in an array. i have it declared as

char firstname[25];
char lastname[25];

but i was told that just stored one string and when i go to print out the names that are input, it just prints the last one i put in in all the slots. So I was wondering what the easiest way to store all the names in the arrays and print them out. The only thing i could find on the internet was to make an array of string arrays , but im not sure how to do that.

Thanks.

Look at it in a normal way. When you are assigning an array to hold a name as firstname[25] it can hold only one string of characters. So if you want to hold more names declare it as firstname[25][25]

With input taken as:

for(i=0;i<25;i++)
gets(char[i]);

When there is one single space for just a name and you go on writing many names in that space it will obviously print the last written name.

csurfer 422 Posting Pro

(Someone's really joking with you when he/she said you to write a compiler in 2 months.In this time you cant even study the basics properly.And moreover you don't know whats LEX and YACC is which can be treated as foundation stones to compiler building.So please stay away from words like bootstrap etc for now.)

Well to deal with your problem in hand the max you can do is to write a C program which takes another file (containing some lines of code like looping etc) as input and splits and tabulates the contents and tries to find a particular pattern there.

csurfer 422 Posting Pro

I need to execute some dos commands like executables(.exe)
PLEASE HELP ME OUT OF THIS

Read more about the "system" command in C language.Your every requisite would get fulfilled.
Through system command you can call all commands you can call in a command prompt mode and also execute certain kinds of files too.

csurfer 422 Posting Pro

i research a code, and it goes like this:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[12],b[12],c[12],i,j=0,k=0;
clrscr();
printf("Enter  12  numbers\n");
for(i=0;i<12;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<12;i++)
{
if((a[i]%2)==0)
{
b[j]=a[i];
j++;
}
else
{
c[k]=a[i];
k++;
}
}
printf("The  even numbers  are\n");
for(i=0;i<j;i++)
{
printf("%d\n",b[i]);
}
printf("The odd numbers are\n");
for(i=0;i<k;i++)
{
printf("%d\n",c[i]);
}
getch();
}

~~but it is so confusing. i have edited it many times but the output is just infinity of numbers.. please help =

The code written by you is perfectly alright(although you have missed out "#" in first statement while putting it up) apart from the fact that you are not using a standard compiler.
The code given by you ran perfectly with the addition of the "#".No other flaws and ya try not to use conio and clrscr and all...

csurfer 422 Posting Pro

first of all thanks for replying...A dictionary from japanse romanji to english and vise versa..and the dictionary data base would be from a single text file....my main prob is how do i get a specific line from that text file
..:D

Well what you really need to do is to create a very large HASH TABLE where in a key has two references ie a word types in japanese(key) with references as the languages you would want to translate that into(meanings). You can work out your needs and the resources and then decide as to which method to choose.

csurfer 422 Posting Pro

The above stated answers by luckychap and salem is what you need to do to make your swing move ie clear and redraw.
But instead of clearing the entire screen its better to clear only a part of the screen.You can just go through the concept of VIEWPORT and move on with it.

csurfer 422 Posting Pro

Well thats a pretty nice approach. Mainly you need to know one thing.Its up to the coder to use his code in the fashion he likes.If you are using these functions only in this program then let it be in main.c itself.
If you think you can use these programs in a broader sense then create a different file poly.c which you can include and continue.
The next step would be a great leap ie If you can bring your functions in the standard ASCII format so that many can use your functions then convert it as a library and header file and let your friends use it and give their feedback.

csurfer 422 Posting Pro

Yes you have really messed up the code at some places :)

Well I wont give you the codes but will help you out in pointing your errors and what you need to add to your codes.Here it goes:

void readA(int A[]){
int A[inte];
printf("\nenter an integer : ");
scanf("%d",A[inte]);
}

This code reads entire array so run a for loop to take in all the inputs you are just taking one input.And ya you are passing array A[] from main and taking it here so why are you re-declaring that array within this function ??? There is no need for int A[inte] within.

void displayA(const int A[],int low, int high){
if(low<=high)
{
printf("%d",A[low]);
displayA(A,low+1,high);
}
}

This code is ok and will fulfill your requisite but don't use "const" at all instances because it may cause big problems if used without caution.

void displayrev(const int A[], int low, int high){
if (a>=0)
printf("\nA[displayrev(a-1)]");
}

This code is nothing. It doesn't even print anything.Your approach to displayA is correct so use the same here in a different way as:

void displayrev(const int A[],int low, int high){
if(low<=high)
{
printf("%d",A[high]);
displayrev(A,low,high-1);
}
}

Now the main() .This is completely useless.

main(){
int A[inte];

printf("Enter the numbers AGAIN : ");
scanf("%d",A[inte]);

}

After the declaration of array A[inte]
call the read array A function written just for that purpose. Once this is done you can move on with your other parts of coding.

And …

csurfer 422 Posting Pro

i already start with simple program,look like it easy, but when come to more complicated program, dont know what to do,

maybe its a late start for me to do programming, i am 33years old, taking online learning, with work and family...

Salem's guidance is really splendid. You need to try once more. You do have very simple inbuilt functions like isalpha(),toupper(),tolower() etc to serve your purpose which you have mentioned in your post.

csurfer 422 Posting Pro

print the decimal, octal and hexadecimal values of all character between the start and stop character entered by user, For example, if the user enters and 'a' and 'z', the program should print all the character between 'a' and 'z' and their respective numerical values.
make sure that the second character entered by the user occur later in the alphabet than the first character. If it does not, write a loop that repeatly asks the user for a valid second character until one is entered

i try this program, but something wrong with the loop function.

Post your program we will be able to solve it hopefully... :)
You must have missed out on very minute detail or something. Try once more.

csurfer 422 Posting Pro

Well when all the functions have been already given in math.h why do you want to re-write them ? You can just take the input in degrees from the user and convert it into radians and feed into functions.

Well if you want to know the basics more and write your own sine cosine programs then here you go:

sin x = x - x^3/3! + x^5/5!......
cos x = 1 - x^2/2! + x^4/4!.......
tan x = sin x / cos x

where x is in radians...
convert above equations into program and you are done...

csurfer 422 Posting Pro

Create a function w/c accepts as input the double numbers x1,x2,x3 and returns to the program the value of the average (x1+x2+x3)/3 as a variable parameter.


#include<stdio.h>
#include<conio.h>
main()
{

i really dont know what next...........

Look programming is like a game.It has its own set of rules. On coding you can get the same satisfaction and fun as in a game.So try your might and play it.
What you really need to do is:
1>Declare some double variables for you to use.
2>Write a function which takes these double variables as parameters with a double value as a return value.
3>From main program call this function by passing these variables x1,x2,x3 and receiving it in another double variable say result.

Note : Until you play the game you don't know how fun it is so try plunging into it even though its hard ( Sometimes ).

csurfer 422 Posting Pro

I just read a while ago that trees can be implemented in some boardgames..can you give me some board games where trees are implemented?

Well SCRABBLE would be the best example I suppose.When the computer plays with its set of letters it branches out and tries all possibilities to make a word which is there in the process of branching and trying for new words trees are used... Because they would be the best way to try out things.