YoTaMiX 0 Light Poster

I have installed FC5 because the board of education in Israel has decided students who learn C and C++ should compile and run in Linux.
I like the GUI , simple enough to use .
however i downloaded an openoffice version who has hebrew support but i cant install it ..... it takes 122MB but no run-file , looks like and archive but i have no idea - new at this Linux business .

YoTaMiX 0 Light Poster

Noone's going to browse through your stuff and fix it all for you.
Copy relevant parts in code tags and show where you have problems, and people will most likely try to help.

public static int EliminatePlayers(int max,int min,int numOfPlayers)
	{
		int killCount=0;
		int retValue=0;
		for (int i=0;i<10;i++)
		{
			if (rollArray[i]==min) 
			{
				players[i]=null;
				rollArray[i]=0;
				killCount++;
			}
			if (rollArray[i]==max) 
			{
				players[i]=null;
				rollArray[i]=0;
				killCount++;
			}
		}
		PrintEliminated();
		System.out.printf("\n ---Next Round--- \n");
		retValue=(numOfPlayers-killCount);
		return retValue;
	}
	public static String ScanForWinner(int playersLeft)
	{
		int winnerIndex=10;
		
		if (playersLeft==1) //Only 1 Player Remains as Winner
		{
		for (int i=0;i<10;i++)
			{
			if (rollArray[i]!=0) winnerIndex=i;
			}
		
		}
		// End of 1 Player Case //
		if (playersLeft==2) 		//2 Players Remain , Including Tie Break Operation
		{
			int tempMaxVal=rollArray[0];
			int maxIndex=0;
			
			for (int i=1;i<10;i++)
			{
				if (tempMaxVal<rollArray[i])
				{
					tempMaxVal=rollArray[i];
					maxIndex=i;
					
				}
			rollArray[maxIndex]=0;	
			for (int j=0;j<10;j++)
			{
				if (rollArray[j]==tempMaxVal)
				{
					while (rollArray[j]==tempMaxVal)
					{
						rollArray[j]=RollDie();
						rollArray[maxIndex]=RollDie();
						if (tempMaxVal<rollArray[j]) 
						   { winnerIndex=j; break; }
						if (tempMaxVal>rollArray[j]) 
						   { winnerIndex=maxIndex; break;}
					}
					if (tempMaxVal<rollArray[j]) 
					   { winnerIndex=j; break; }
					if (tempMaxVal>rollArray[j]) 
					   { winnerIndex=maxIndex; break;}
					
				}
			}
		}
		winnerIndex=maxIndex;
	}
			return players[winnerIndex];
}

public void GamePlay()
	{
		int maxInRoll;	 //Max Value in Round
		int minInRoll;	 //Min Value in Round
		int maxCount=0;	//Counts holding Max Value
		int minCount=0;	//Counts holding Min Value
		int playersRemainCount=10; //Players Remains InGame Count
		
		CreateRound(playersRemainCount); 	//First Round
		
		while ((playersRemainCount>2)) //Condition for GamePlay to Continue
		{
			minInRoll=findMinInArray(); 	//Finds Min in Round
			maxInRoll=findMaxInArray(); 	//Finds Max in Round
			maxCount=CountMax(maxInRoll); 	//Counts for Max
			minCount=CountMin(minInRoll); 	//Counts for Min
			System.out.printf("MinCount is %d = Min  %d , Max Count is …
YoTaMiX 0 Light Poster

Hello to you all ,

I am attaching a HW project which i made in Eclipse 3.2 Enviorment.
It is a Cube tourney that each game consists 10 players.
Round 1 is 100 Games , each winner is sent to the SemiFinal.
than 10 Games of Semi - each winner sent to final, than final game.

The rules : until 1 or 2 players remain , the players with Max Result and Min Result in each Randomized Roll of the Polygon ( 13 faces) are out.
conditions : if MinCount + MaxCount = PlayersRemainedCount there has to be a new Roll of the Polygon to all of them and re-check conditions.
If 1 players Remains - he wins. If 2 remain , the player with the highest roll result wins.

Bugs : Duplicate names in SemiFinal and Final games , somehow the are being repeated after i reset the array of rolls and names. I have spent 5 hours to try and find it ... i didnt. i am in a pool of poo :cheesy:

Thanx , i have 30 hours to submit it for a grade .(Wrapped in ZIP File)

Yotam , Israel .

YoTaMiX 0 Light Poster
int start = 1;
  int max = 10;

    for ( int i = start; i < max + 1; i++ )
    {
        for ( int j = start; j < max + 1; j++)
        {
            system.out.print ( i * j + "\t%d");
        }
         system.out.println("");
    }

My output:

1       2       3       4       5       6       7       8       9       10

2       4       6       8       10      12      14      16      18      20

3       6       9       12      15      18      21      24      27      30

4       8       12      16      20      24      28      32      36      40

5       10      15      20      25      30      35      40      45      50

6       12      18      24      30      36      42      48      54      60

7       14      21      28      35      42      49      56      63      70

8       16      24      32      40      48      56      64      72      80

9       18      27      36      45      54      63      72      81      90

10      20      30      40      50      60      70      80      90      100

Actually that don't work oops.

I wish to get 10 numbers from User and store them somehow without an array for that matter and get the same MultiTable to those numbers.
Its very tricky , i tried using some sort of SUM Varieble but couldnt make it work

YoTaMiX 0 Light Poster
* 
 */
import java.util.Scanner;

/**
 * @author Yotam Golomb ID 040435497
 *
 */
public class MultiTableProg {

	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		int temp;
		int sum=1;
		System.out.println("Welcome to HomeWork 1.");
		System.out.println("Please Enter 10 Numbers , Range 1 to 50");
		
		for (int i=1;i<11;i++)
		{
			temp=input.nextInt();
			for (int j=1;j<11;j++)
			{
			
			System.out.printf("\t%d",sum*temp);
			sum=temp;
			}
		System.out.printf("\n");
		
		}
		
		
		
	}

}

What do u expect the code to do?

Well , i.e. :
if the input is numbers from 1 to 10 :
1 2 3 4 5 6 7 8 9 10
2 4 ...................20
3 6....................30
4 8....................40
5 10 .
6 12 .
7 14 .
8 16 .
9 18 .
10 20............... 100

I hope the Example is helpful.

thanx again , Yotam

YoTaMiX 0 Light Poster

Hello to all the Readers ,

I am trying to create a Multi-Table from 10 Numbers given by a user.
I cant figure it out why the Multitable isnt shown correctly. I tried
to enter the 1-10 numbers to get the result we all know and still nothing good came out.

thank you for you help , Code is Attached . :)

Yotam , Israel.

YoTaMiX 0 Light Poster

Nope, no code was attached. Why don't you just post it using code tags anyways?

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

typedef struct Queue
{
 int first;
 int full_size;
 int present_size;
 void** place;
}queue, *q_ptr;

//__ PROTOTYPES __//
char* MakeString();

q_ptr Create(int);
void Enqueue(void* Element,q_ptr Q);
void Dequeue(q_ptr Q);
void GetSize(q_ptr Q);
void ShowQ_Str(q_ptr Q);

void main()
{
 q_ptr Q;
 int choise,limit;

clrscr();
printf("Welcome to HW8 - String Example for Void* Queue\n");
printf("Please Choose of the Following : \n");
printf("1. Work with String \n2. Exit from HW8\n");
scanf("%d",&choise);
switch (choise)
      {
	case 1: {
	       int op=0;
	       printf("Enter Size you Wish To Limit Queue\n");
	       scanf("%d",&limit);
	       Q=Create(limit);
	       while (op!=4)                    //Repeat Menu
	       {
		printf("Choose of the Following Operations : \n");
		printf("1.Enqueue\n2.Dequeue\n3.Get Size of Queue\n4.Exit\n");
		scanf("%d",&op);
		switch (op)
		{
		case 1: {                       //Enqueue
			 char* Str=NULL;
			 Str=MakeString();
			 Enqueue(&Str,Q);
			 flushall();
			 break;
			}
		case 2: { Dequeue(Q); break; }  //Dequeue
		case 3: { GetSize(Q); break; }  //Get Size
		case 4: { ShowQ_Str(Q); getch(); free(Q->place); free(Q); exit(1); break; }     //Exit Program
		}
	       } //End Menu Of Queue
	case 2: { printf("Bye Bye\n"); exit(1); break; } //Exit Program
	}
     }

}

void ShowQ_Str(q_ptr Q)
{
int j;
for (j=0;j<Q->present_size;j++)
  printf("Q Place [%d] is %s \n",j,*(char*)(Q->place[j]));

}

char* MakeString()
{
 char* temp;
 printf("Enter String\n");
 gets(temp);
 return temp;
}

q_ptr Create(int limit_size)
{
 q_ptr new_q;
 new_q=(q_ptr)malloc(sizeof(queue));
 if (new_q==NULL) { printf("Error in Queue Alloc , Bye \n"); exit(1); }
 new_q->first=new_q->present_size=0;
 new_q->full_size=limit_size;
 return new_q;
}

void Enqueue(void* Element,q_ptr Q)
{
 int i;
 if ( (Q->first==0) )
    {
    Q->place=(void**)malloc(sizeof(void*));
    if (Q->place==NULL)
	{ printf("No Q 4 …
YoTaMiX 0 Light Poster

Hello to you all ,

I am Trying to Implement Code for Void** Array which will Store
Strings in a QUEUE system .
I can see the Strings in the Queue .
I am sure i dis the Casting OK, But i need a fresh pair of eyes.
Also is there a way to REALLOC The array each Dequeue?

Thanx

Yotam , Israel

P.S Code Attached - Using Regular C Compiler (Borland)

YoTaMiX 0 Light Poster

yes -- how else can the program pass the correct data type to printf(). There is another solution -- create a union of data types than an array of union objects

typedef union
{
    short sVal;
    int iVal;
    long lVal;
    float fVal;
    double dVal;
}DATA;

...
DATA* array = malloc(some_number * sizeof(DATA));
...
scanf("%d",&array[loop].iVal);

so you are suggesting a Struct of Type to Use and DATA is the field itself?
1= sVal and so on? :-)
we are forced to use VOID* ARRAY ... :-)
anyhow , after i store the data , i need to find the two smallest values.

the prototype is :
void two_min(int(*comp)(void* a, void* b), void **answer, void **array);

and i need to compare functions for each type , 1 Int , 1 Float :

int Compare_Number( void* a , void* b)
{
return *(int*)a - *(int*)b;
}
and the same for float , right?

the requirement is that i need to go over the Data Array only once for each cell in array. is it possible?

YoTaMiX 0 Light Poster

thank you :-)
follow up question - if i wish to print out the array , do i need typecasting as well , like in Scanf ?

YoTaMiX 0 Light Poster

Hello ,

I wish to create a User-Defined array (1=float , 2=int) and to ALLOC
the array properly. I defined void* ARR in main function
and is a SWITCH (choise) i will make the desired array.

why doesnt it work?

Code is attached .

thanks :-)

YoTaMiX 0 Light Poster

I already told you. Dont do this :

free(top);
    top=top->next;

Its very wrong !!!!!
And still you do it again !!!!
:mad:


First thing better change input by getche to fgets.


Do you think that this is nessary ???
if ( (temp==')') || (temp==']') || (temp=='}') )
{ printf("\n Bad Expression! Run it Again... \n");

add to

case ')': { flag=check(temp[i]);  }
       case ']': { flag=check(temp[i]);  }
       case '}': { flag=check(temp[i]);  }

break statemnts!


If the stack is not empty thats wrong

if ( top )
   {
   printf("Items on the stack\n");
   flag = 0;
   }

You are ignoring the case which pop returns zero.


last thing
'(' - ')' == -1

A few things :
1. how do you Take off the Top each time if not in that way?
2. Added Break Statements , still causes problems in Expression check ,
each EXP check gets OK ....
3. the If sentence - no Math Exp. starts with backwoards brackets. :-)
4. should i pass into the POP function a Pointer to FLAG ?

Thanx

YoTaMiX 0 Light Poster
The logic should be like this :
   while ( input != 13 )
      {
       if input is '(' or '{' or '[' or ')' or '}' or ']' 
          {
          if input is '(' or '{' or '['
              push it into the stack.
          else if input is  ')' or '}' or ']' 
              {
              if stack is empty
                       report error.
              pop cell from stack
              if cell "matches input" 
                       we are ok.
              else if cell dont "matches input" or stack is empty 
                       report error.
              }
          }
      }
   if  the stack is not empty
        report error.

Also I would suggest replacing your input function
with fgets.
A nice touch would be to add to the switch statment
a default case, checking if it is a number of math experssion.
Don't ever write code like this :

free(top);
    top=top->next;

Once you free(p), dont access it !!!!!!!!!!
It will probaly work, but its wrong, and
also your grade will be like it.

I see your point :-)
i build something , but for some reason , it will state all Expression are OK and i tried to Debug it , and i cant figure what went wrong... Code Added . The check is though ASCII code :
'(' - ')' = 1
'' = 2
'{' - '}' = 2

Thanx

YoTaMiX 0 Light Poster

Hello to you all ,

I am required to write a program which gets a Math Expression (without checking it is good) and put in Stack only the Brackets .
Implementation of Stack is One-Way Linked List Only.

Examples for Good/Bad Expressions :
(a*{b+c}-4/x +[e-5]) - GOOD
(5+} - BAD
(5+{6*)-2} - BAD
(5+z - BAD

I have build up a Mechanism which checks for each entered char (other than Enter Key and also using closing brackets such as ) or ] or } at the beginning of Expression) what type of bracket it is and pushes it into a stack (we must use LIFO technique for check legal Expression).

I thought of 2 cases :

first case : for each open bracket there is a closing one so i check top of stack to bottom of stack and carry on till i reach to middle .
second case : what happens if i have this sequence - ()[]{} - meaning i need to check top against the next , and so on (top of stack to bottom of stack will not help in this case)

I kinda stuck on Algorithm Think Phase :-)

Code Added . Any Ideas ?

Thank you , Yotam , Israel

YoTaMiX 0 Light Poster

Hello :-)

I have build a task of Linked List but for some reason , after i break the Input sequence by entering the same INT value twice in a row , the menu appears twice . howcome?

Thank , Code Attached .

Yotam

YoTaMiX 0 Light Poster

that code is actually adding 1 in place of index ?

YoTaMiX 0 Light Poster

Hello :)

i need to write a program which gets from user number and index
( 0 <= number <= 255 , 0<=index<=7) .
then to add up to the number in bitwise a 1 in the place of the index :
if number is 102 which is 01100110
and index is 4 which is 01110110
and get 118 as a result.

for some reason it doesnt do that ..... i have no idea why , i used OR operation between numbers ..... :rolleyes:

Code added

thanx , Yotam

YoTaMiX 0 Light Poster

Evening :)

I am trying to run a makefile on a program i wrote.
in Borland C it runs smoothly .
after running the makefile - all sorts of error appear which i do not understand.
i am adding the files (program + header + error DOC ) .

Makefile as written :

hw_2 : ex.o main.o
gcc -o hw_2 ex.o main.o
ex.o : hw2head.c hw2head.h
gcc -c -x c hw2head.c
main.o : hw2cpy.c hw2head.h
gcc -c -x c hw2cpy.c[


Thank you in advance ,

Yotam , Israel.

YoTaMiX 0 Light Poster

In function input_university() I see where scanf() is reading the string, and univ->std[num_cells].name is getting allocated, but I don't see where it is copying buffer to univ->std[num_cells].name after allocation. Add this and it will probably work ok.

strcpy(univ->std[num_cells].name,buffer);

I did just that . now it messes up another string - i'll figure it out
somehow , the thing is , we were never tought the subject BUFSIZ and
"sscanf" - so no offence there ;)
i got slapped on using it .... sorry

YoTaMiX 0 Light Poster

Apparently, I wasted my time :mad:
http://www.daniweb.com/techtalkforums/thread43435.html

Not only have you dropped the initialisation of univ in main(), but you've gone back to using fscanf to read the file.
Not only that, you're now using global variables like "temp", which get allocated on every iteration of the loop and never freed.
Don't forget the not using a temporary variable when calling realloc, nor the unnecessary casting of malloc and realloc.

Y'know what, if you're just going to ignore people, just say so - ok?

I guess i didnt see it - sorry mate :confused:

YoTaMiX 0 Light Poster

Hello to you all ,

Major problem in C , Files included

Summary of problem :
Program will not copy the feild "name" from struct "univ->std.name" properly. the rest of data is presented fairly.
do not touch function "output_university" .

Thank you ,

yotam , Israel .

YoTaMiX 0 Light Poster

i ment - i can't figure it :) LOL

YoTaMiX 0 Light Poster

Hello to you all ,

I have a program who i want to copy one input.txt to a output.txt
and for some reason it duplicates the string and it doest create a full duplicate .

i am over this for a few hours now and i can figure it out.

can you help me?

Input file and source is attached , neutrilze the Z option in the Menu

thanx :)

YoTaMiX 0 Light Poster

> void main
main returns int

> char user_choice;
> while (user_choice!='z')
This variable is uninitialised at the point you first use it.

> university univ;
This isn't initialised either.
Which is very important when you get to make_file(), since you do
- dereference an uninitialised pointer
- try and realloc an uninitialised pointer

> if (un->ptr==NULL) un->ptr=(student*)realloc(un->ptr,(count+1)*sizeof(student));
The test serves no purpose, since at best it only extends the array once.

In main(), you need this to start off with a NULL pointer university univ = { 0 }; And this function needs to be something like

int make_file(FILE *in,university *un) {
  char buff[BUFSIZ];
  int  count=0;

  while ( fgets( buff, sizeof buff, in ) != NULL ) {
    student s;
    if ( sscanf( buff, "%s %ld %f %ld",
                 s.name, &s.id, &s.avg, &s.hw_submit ) == 4 ) {
      /* success decode, extend array and copy the info */
      void *temp = realloc( un->ptr, (count+1)*sizeof(student) );
      if ( temp != NULL ) {
        un->ptr = temp;          /* update array */
        un->ptr[count] = s;      /* copy data */
        count++;                 /* one more stored */
      } else {
        /* no more room, return with what we have */
        return count;
      }
    } else {
      /* that line didn't make sense, report it */
      fprintf( stderr, "Bad line %s", buff );
    }
  }
  return count;
}

I did so , however , only the first name was fixed .... how bizzare.
1. what does "buff" …

YoTaMiX 0 Light Poster

Hello to you all ,

I am having a little trouble in C , working with Files.
for some reason , it doesnt copy to output file the first letter and jumps
over 3 digits of the last number in the file .

whats wrong , i cant find it .

yotam

P.S - source and Input.txt included

YoTaMiX 0 Light Poster

thanx , that will suffice :-) cheers!

YoTaMiX 0 Light Poster

its foolish that in the function every time u r initializing i with 0 and returning home if null or not moving further because u still are with i=0 in the remaining iterations also.

solution to ur code is declare ur int as static int.
then the problem is solved

get help at >>> prof.thakur@yahoo.co.in

I am putting up the code in attachment.... i tried watching the process and i still cant find whats wrong

thanx :D

YoTaMiX 0 Light Poster

Code :

int func(char s1[], char s2[])
{
 int i=0;
  if (s1[i]!=s2[i]) return 0;
  if (s1[i]==s2[i]) return 1+func(s1[i+1],s2[i+1]);
}

/QUOTE]
>>if (s1!=s2) return 0;
here think what happens if the first character does not match
does it remain the type of function you want..
and you need sum kind of parameter checking to end the recursive loop
add the condition of some kind

sanket

the first IF is the stop condition for loop , if first letter doesnt match , it will not run on the rest of the strings. no?

yotam

YoTaMiX 0 Light Poster

Hello to you all ,

I have been assigned to in C to build a function which will take 2 strings and count (in recursive way) how many chars are alike (case sensitive).
I have setup the main and also a function which recieves the input from user .

I have a problem converting the theory to commands :

if the function recieves 2 strings , the comparison needs to letter to letter with the same index , and adding 1 to the returned value if they are equal, in which the advance down the recursive process is "index+1".

I tried it , but it doesnt work and i have no idea howcome .

Code :

int func(char s1[], char s2[])
{
int i=0;
if (s1!=s2) return 0;
if (s1==s2) return 1+func(s1[i+1],s2[i+1]);
}

am i missing something ?

thank you

Yotam :D

YoTaMiX 0 Light Poster

where is it located , the compiler in the Fedora System .... i cant find it

YoTaMiX 0 Light Poster

Hello :-)

I have installed Fedora Core 4 and we learn in college C++ .
where can i find a C++ author and compiler for Fedora Core 4?

Thank you

YoTaMiX 0 Light Poster

Hello ,
I wish to Duplicate certain Fields in the same tables when i open a new form that is related to that same table .
If i create a button of Duplicate Record , he will duplicate the Primary Key - which i do not want to "Duplicate OK" .

Thanx , Yotam , Israel

YoTaMiX 0 Light Poster

Hello to you all ,

i have recieved an assignment to build a recursive function
which will recieve an array which has to check if it is "Up&Down" from both sides : Example : 2 5 6 12 7 5 2 .
according to the specs of the H.W assignment , i need to find an "extreme value" (in example - 12) .

how should i approach this?

Thank you

Yotam

YoTaMiX 0 Light Poster

Hello to you All ,

For some reason , the Compiler throws me an Error
"Illegal Operation" on the Comparison described below :

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

typedef struct {
double x,y;
} Point;

typedef struct {
Point l, r;
} Rectangle;

typedef struct {
Point Center;
double r;
} Circle;


int main()
{
Circle user_c;
Rectangle user_r;
Point user_p;

printf("Please Enter Upper Right Corner , Lower Left Corner , Point X and Y\n");
scanf("%ld%ld%ld%ld",&user_r.r,&user_r.l,&user_p.x,&user_p.y);
if ( ((user_p.x) > (user_r.r)) && ( (user_p.x) < (user_r.l)) )
printf("OK");

return 0;
}

YoTaMiX 0 Light Poster

Thanx , i hope i can use it :-)

YoTaMiX 0 Light Poster

Hello again ,

I am adding the Code for the Prog .... where the remarks are,
its is where i stuck . thanx again

YoTaMiX 0 Light Poster

question : how Qsort will help me? if a 2D array is one big 1D arrray , should i work line by line ?

YoTaMiX 0 Light Poster

Hello you all!!!
I got an Assignment to sort a Randomized Dynamic 2D Matrix of Integers , Snake style : for Example : biggest number in row 0 , after it follows (beneath it , vividly) the next number :

1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25

(after Sort for example) .
it has to be as less time complex as possible.... and i am stuck. Thanx a lot