riahc3 50 Â Team Colleague

Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?

riahc3 50 Â Team Colleague

Can I use another complier using the MS VS 6 GUI?


That would be perfect for me.
Ive been taught C this way. Besides the point its stupid to do a malloc (in this case) and this is a few lines of a program.

riahc3 50 Â Team Colleague

And is there a way to make it comply in MS VS 6?

riahc3 50 Â Team Colleague

Hey

Why does the following code comply in Dev-C++ and it DOESNT in MS VS 6.0?

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <float.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void main()
{
	int num;


	
	printf ("Number of positions");
	scanf ("%d",&num);
	int vector[num];
	
}
riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

Well, the simplest way to make a blank image on your drive is to do something like this: dd if=/dev/zero of=filename.img bs=512 count=102400 That will create a 50 MB disk image with 102400 512-byte blocks (102400 blocks/2 blocks in a kB/1024 kB in a MB = 50 MB), and the image will be filled with zeros.

You can create an alternate version where the zeros are implied, but they aren't written to disk. Therefore, the disk image is sparse and will only use up the amount of space that data is actually occupying (as compared to the previous image, which will use 50 MB of disk space regardless of what's stored on it). dd of=filename.img bs=512 count=0 seek=102400 Finally, here's how you create a filesystem on it and store files. First, associate a loop device with your disk image. Usually /dev/loop0 is available for this (although if you've got some other disk images mounted, use the next available loop device). Note that you need root permissions for the following commands. losetup /dev/loop0 filename.img Now that you've got an associated loopback device, you can create your filesystem: mke2fs /dev/loop0 Finally, you can mount the filesystem: mount -t ext2 /dev/loop0 /mnt I'll leave the encryption up to you.

Thank you very much for the explanation :)

The problem is Ive already looked up encryption for more than a week and a half but havent found anything. And I thought that /dev/loop had something to do with encryption instead of mounting it …

riahc3 50 Â Team Colleague

Hey

I want to make a VHDD (V.irtual H.ard D.rive D.isc) using the dd command and then encrypt it. I was told I had to do something with loop also to encrypt it but cant find anything. I dont want to experiment as dd is VERY powerful and can fuck up my drive. Thanks :)

riahc3 50 Â Team Colleague

I figured it out :) Had to run the seed outside of the do-while loop. Worked great.

One last question: Do I have to run srand(time(0)); only once in the entire program or each time I run a function called "int numbergenerator" which returns the random number?

Ill explain with code

running srand(time(0)); once:

void main()
{ 
int num;
srand(time(0));
int=numbergenerator;
}

int numbergenerator()
{
int num;
char c; //DO NOT PAY ATTENTION TO THIS. IT IS JUST SO THE DO-LOOP DOESN'T END AND GENERATES INFINITE TIMES AS A TEST
do
{
num=rand() % 4;
printf ("number %i",num);
getch(c);
while (c!="x"); //DO NOT PAY ATTENTION TO THIS. IT IS JUST SO THE DO-LOOP DOESN'T END AND GENERATES INFINITE AS A TEST
return num;
}

running srand(time(0)) each time

void main()
{ 
int num;
int=numbergenerator;
}

int numbergenerator()
{
int num;
char c; //DO NOT PAY ATTENTION TO THIS. IT IS JUST SO THE DO-LOOP DOESN'T END AND GENERATES INFINITE TIMES AS A TEST
srand(time(0))
do
{
num=rand() % 4;
printf ("number %i",num);
getch(c);
while (c!="x"); //DO NOT PAY ATTENTION TO THIS. IT IS JUST SO THE DO-LOOP DOESN'T END AND GENERATES INFINITE AS A TEST
return num;
}
riahc3 50 Â Team Colleague

You asked for 0-3 right? How many numbers are that? Holy ****! It's four!


You really aren't the sharpest knife in the shed are you?

I'll give it a try :
You. Read. Tutorial.
Click this blue underlined word

Again this is for C++, not C.

It is obvious that you are a complete asshole; Some are just starting out or simply need help to understand a certain area

#include <stdlib.h> /* needed for rand() function */
#include <time.h> /*needed to call srand() (explained below)*/

int main(void)
{
	int r = 0;

	/* by calling this function, we seed the random number generator. If we don't seed it, we will get the
	same numbers every time we generate random numbers*/
	srand(time(0)); 

	/* rand() returns a number from 0 to RAND_MAX (you can output it to see)
	by using the % (modulus) operator on a number, the number you will get is from 0 to number-1 */
	r = rand() % 4;  /* so this returns a number from 0 to 3 */

	r = 1 + rand() % 4; /* 1 to 4  and so on*/

	return 0;
}

Thank you for posting this code. It works but my only problem is that (in a do-while loop) it generates 0 about 10-15 times then 3 another 10-15 times then 3 another 10-15 times then 2 another 10-15 times then 1 another 10-15 times then 0 again and all over again....

riahc3 50 Â Team Colleague

>I do not understand the code. Thats why I wanted a page in C that
>tells me how to use rand()/srand() to generate a number between 0 and 3.
Sorry, I'm not smart enough to dumb it down enough for you to understand. If you can't take int r = rand() % N; and turn it into int r = rand() % 4; with a two full tutorials backing it up, you're clearly out of my league.

So what: N is now 4? But because you say so? And why 4/n?

If there is a page that explains the part of the funtion and the parameters, thats what Im looking for.

riahc3 50 Â Team Colleague

I do not understand the code. Thats why I wanted a page in C that tells me how to use rand()/srand() to generate a number between 0 and 3.

riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

Is there a good webpage that explains how to use rand() and srand() correctly? Overall I need to learn how to generate a number between 0 and 3.

riahc3 50 Â Team Colleague

>I just want to hit one key and not enter the option then have to hit the enter key.
There's no portable way to do this. You have to rely on a non-standard function like getch.

Fine by me :) Getch is "standard" in VS so It'll work in my case. Nonstandard functions (as long as its nothing really weird) are OK.

riahc3 50 Â Team Colleague

Hey

I have this code:

void menu()
{
char opt
do
{
system ("cls");
printf ("1 - Option 1");
printf ("2 - Option 2");
printf ("3 - Option 3");
[B]scanf ("%c",&opt);[/B]
[B]}while ((opt!="1") && (opt!="2") && (opt!="3"));[/B]

The lines in bold are the ones Im not sure about.

What I want to do is a menu that displays, the cursor blinks, and I have to press a key (In this case 1, 2 or 3) and as soon as I press it, it enters the option (by using a case which I understand for now). If incorrect it simply displays the menu again. I just want to hit one key and not enter the option then have to hit the enter key.

riahc3 50 Â Team Colleague

You should be able to store the data for each card within an integer. You could then get the suit as card / 10 and you could get the rank as card % 10. I find this approach simplifies things a little.

Not getting this fully. The suit and the rank is where you lost me

You could then have an array size 40 to hold the cards, which would be shuffled when you start the game.

This was one of my ideas. Actually two seperate arrays; one with the organized get and another with the unorganized deck with would get it from the organized one.

Instead of passing structs around between the deck an the players you keep an index of the stack position in the deck. Every time you deal a card copy the card value at the stack position to the players hand and increment the stack position. When you reach the end of the deck the you can reshuffle the cards or something.

Im sorry but here I honestly have no idea what you are talking about.

Structs is something Im use to working with.

Heres crude example of how to get a random number:

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

int main()
{
	srand(time(NULL)); 		//seed randomisation only once at start of game

        printf("Random number (0 - 39): %d\n", rand() % 40); // print a random umber
	return 0;	
}

Ah yes. Thats what it was. Thank you very much.

A simple …

riahc3 50 Â Team Colleague

I just wanna know if the idea is right or not.

riahc3 50 Â Team Colleague

I hope you understand what I ment with my last post.

riahc3 50 Â Team Colleague

Look into the time functions in timer.h for ways to do the counters. If you need help in other areas, please be specific.

My thinking on how to do these things...Is it correct or is another method better?

riahc3 50 Â Team Colleague

Hey

I have to make the game War (card game: http://en.wikipedia.org/wiki/War_(card_game) ) in C. Im not sure where (how...) to start. My basic thoughts/ideas/etc:

Its a 40 (4 times 10) card version with 2 players. A way to do it would be set up a structure with 4 faces values: a, b, c, and d. Now I need that each has a value of 1 - 10 (a1, a2, a3....a10) but nonchanging. After this each player has a another structure (or array (?) ) holding 20 cards. Now out of the 40 card deck structure we have to randomly pick them out and assign them to the 2 players (this is one of the 2 big problems; No idea how to randomly pick)

The game afterwards is pretty simple: Simply each player puts out a card. If the card is larger, that player gets his card back (in a seperete deck) and the other players card. If the card is smaller, the player looses his card. If tie, player puts 2 cards with hidden value and a third card with value revelaed. That shouldnt be too hard. The game is ended when a player is without cards

Now here a hard part: There will be a clock running during the game. If someone beats the game and is in the top 10 of the fastest, his name will be added to the ranking. This is saved/loaded from a simple text file. I have no …

riahc3 50 Â Team Colleague

I searched but I can't find where I redeclare my .h files in .c more than once...Ive looked several times but just can't see it.

riahc3 50 Â Team Colleague

Hey :)

Damn I hate pointers in C :P Worse thing possible. Anything I post my code:

main.c

#include <assert.h> 
#include <ctype.h> 
#include <errno.h> 
#include <float.h> 
#include <iso646.h> 
#include <limits.h> 
#include <locale.h> 
#include <math.h> 
#include <setjmp.h> 
#include <signal.h> 
#include <stdarg.h> 
#include <stddef.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>
#include <time.h> 
#include <wchar.h> 
#include <wctype.h> 
#include <conio.h>


#include "estructuras.h"
#include "funciones.h"
#include "menus.h"


#define num 999

/* Localizado en menus.h */
void menuprincipal(cli *);
//void menucliente(cli *);
//void menuproductos();
//void menuempleado();



/* Localizado en funciones.h */
//void inicializar ();
//void confirmarcliente();
//void insertarcliente(cli *);
//void insertarempleado();
//void mostrarcliente(cli *);
//void inicializarporarchivo(cli *);



void main()
{
	
	cli *pc;
	pro *pp;
	emp *pe;

 	*pc=c[0];
	*pp=p[0];
	*pe=e[0];


	
	
	
	
		

	
	
	
	
	
//system("cls");
//inicializar();
//menuprincipal();
	//inicializarporarchivo(pc,pp,pe);
	menuprincipal(*pc);
	//guardarenfichero();
}

estructuras.h

#define num 999 // Para que sean todos las estructuras de 999

/* Estructuras principales */
struct direccion
		{
			char calle[15]; //Limitado a 15 characteres
			int numportal; //1 digito
			int piso; //1 digito
}; 
struct poblacion
		{
			char nombrepoblacion[15]; //Limitado a 15 characteres
			int codpostal; //Limitado a 5 digitos
			char provincia[15]; //Limitado a 15 characteres
}; 

struct empleados
{
	int id; // Limitado a una letra E seguido de 3 numeros
	char dni[11]; //Limitado a 8 numeros, un guion y una letra
	char nombre[15]; //Limitado a 15 characteres
	char apellido[15]; //Limitado a 15 characteres
	int telefono; //Limitado a 9 digitos
	struct direccion dir; // Una variable que es de tipo estructura dirrecion: acesso a calle,
						  //Numportal, y piso
	struct poblacion pob; // Una variable que …
riahc3 50 Â Team Colleague

Heres my code if anyone is intrested:

Public Class Reparaciones
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btn_alta As System.Windows.Forms.Button
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents cmb_productos As System.Windows.Forms.ComboBox
    Friend WithEvents txt_unidades As System.Windows.Forms.TextBox
    Friend WithEvents lbl_unidades As System.Windows.Forms.Label
    Friend WithEvents lbl_producto As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents txt_fecha As System.Windows.Forms.TextBox
    Friend WithEvents cmb_matricula As System.Windows.Forms.ComboBox
    Friend WithEvents txt_horasreparacion As System.Windows.Forms.TextBox
    Friend WithEvents txt_preciohora As System.Windows.Forms.TextBox
    Friend WithEvents txt_dni As System.Windows.Forms.TextBox
    Friend WithEvents lbl_horasrepa As System.Windows.Forms.Label
    Friend WithEvents lbl_preciohora As System.Windows.Forms.Label
    Friend WithEvents lbl_fecha As System.Windows.Forms.Label
    Friend WithEvents lbl_matr As System.Windows.Forms.Label
    Friend WithEvents lbl_dni As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btn_alta = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.cmb_productos = New System.Windows.Forms.ComboBox
        Me.txt_unidades = New System.Windows.Forms.TextBox
        Me.lbl_unidades = New System.Windows.Forms.Label
        Me.lbl_producto = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.txt_fecha = New System.Windows.Forms.TextBox
        Me.cmb_matricula = New System.Windows.Forms.ComboBox
        Me.txt_horasreparacion = New System.Windows.Forms.TextBox
        Me.txt_preciohora = New System.Windows.Forms.TextBox
        Me.txt_dni …
riahc3 50 Â Team Colleague

Hey :)

How do I load data from a Access DB into a combobox?

riahc3 50 Â Team Colleague

Can anyone explain the code please?

riahc3 50 Â Team Colleague

Well, i think you are increasing your problem a lot, remember that a struct look in the "computer way" is just like an array, or a matrx, "a conjunt of bytes", so, you may use fread to retrieve all data from your file:

fread(&myStructInstance, sizeof(MyStruct), totalElements, myFilePtr);

no matter how many elements you have in your struct, nor the total amount of tupples on your file, fread will try to fill your structure instance as with many data as he can get from the stream.

since you can get/store the information, (store is with fwrite at the same way) you may use a pointer of type of your structure to walk on every struct elements:

struct *myStructPtr;
myStructPtr = myStructInstance;
for (i =0; i<999;i++) {
/* Use mystructptr with the arrow operand (->) */
}

Maybe you should abstract the ideas for retrieving and storing data into a different file, you you can reuse those code in handling all your structures

Hope it helps

P.D. To proper use fread and fwrite you need to open your file in binary mode (just add an "b" to the "opening flags"

Like I said, I havent been informed about the fread function so I dont think ill be using something that I have to read about and learn quickly to implant it.

Describe this code a bit better:

struct *myStructPtr;
myStructPtr = myStructInstance;
for (i =0; i<999;i++) {
  /* Use mystructptr with the arrow operand (->) */ …
riahc3 50 Â Team Colleague

If you need to reopen it for writing, why don't you open it for reading and writing "rw" or reopen it with freopen()?

Because Ive been show that its more secure to open and close it....
Don't know about freopen.

feof() returns a nonzero value when the FILE has reached the EOF. Your while-loop checks if it doesn't equal one, but it should check if it equals 0: it may not return 1, it may return any nonzero number. This doesn't have to be a problem, but it's more secure.

I understand and Ill fix this :)

If you haven't read anything about memset, you don't know how to initialize arrays. Which is kinda bad. You can set the whole c[], p[] and other arrays to 0 or any value you prefer with memset. Read up on it. It'd make the program more readable and faster.

Well to initialize a array we weren't shown using memset....

By the way, here's a nice reference:
http://www.cppreference.com/index.html

Thanks.

Thanks BTW for all your help Clockowl. :)

I have another question but related.

As you see I have

c[num] for my structs.
How can I use a pointer to go thru all 999 positions for the struct? Pointers and file handling are my weakpoints; Any more pages about these subjects would be great. Again thanks Clockowl

riahc3 50 Â Team Colleague

in inicializar():Better to use memset to clear them, or only set the first byte to the NULL byte.

I havent read anythning about that so that isnt a option

in inicializarporarchivo:
char tid[1];
char ttelefono[9];
char tcantcompras[1];
char tnumportal[2];
char tpiso[1];

tid, tcantcompras, tpiso: char arrays of a single char?

Yes that was kind of stupid because I was stressed.

How do your files look? Your only using fgets, which reads in a file until it encounters a '\n'. Is that correct?

I dont understand this very well but my files are like this:

Client 1:
1234567-L
David
James

So each line (\n) is read and inserted into each field in the struct. Is that the correct way to do it?

You're trying to use putc on a file which you opened as "r"eadonly. That' can't be correct.

I dont use putc in anywhere...except maybe when it is NULL and it has to close and open it as write...

You're testing "feof()" with "!= 1". Better would it be to continue when "feof == 0", since TRUE isn't defined as 1 but as any non-zero number.

Reexplain this please.

riahc3 50 Â Team Colleague

OK here's the code for my structs:

#define num 999 // Para que sean todos las estructuras de 999

/* Estructuras principales */
struct direccion
		{
			char calle[15]; //Limitado a 15 characteres
			int numportal; //1 digito
			int piso; //1 digito
}; 
struct poblacion
		{
			char nombrepoblacion[15]; //Limitado a 15 characteres
			int codpostal; //Limitado a 5 digitos
			char provincia[15]; //Limitado a 15 characteres
}; 

struct empleados
{
	int id; // Limitado a una letra E seguido de 3 numeros
	char dni[11]; //Limitado a 8 numeros, un guion y una letra
	char nombre[15]; //Limitado a 15 characteres
	char apellido[15]; //Limitado a 15 characteres
	int telefono; //Limitado a 9 digitos
	struct direccion dir; // Una variable que es de tipo estructura dirrecion: acesso a calle,
						  //Numportal, y piso
	struct poblacion pob; // Una variable que es de tipo estructura poblacion: accesso a
						  // nombrepoblacion, codpostal, y provincia
}e[num]; 
/* Asi podemos insertar hasta 999 productos, porque he creado 
la tabla que contiene num elementos de tipo empleados: Este numero es el mismo que el id */



struct clientes
{
	int id; // Limitado a una letra C seguido de 3 numeros
	char dni[11]; //Limitado a 8 numeros, un espacio y una letra
	char nombre[15];//Limitado a 15 characteres
	char apellido[15];//Limitado a 15 characteres
	int telefono;//Limitado a 6 digitos
	struct direccion dir; // Una variable que es de tipo estructura dirrecion: acesso a calle,
						  //Numportal, y piso
	struct poblacion pob; // Una variable que es de tipo estructura poblacion: accesso a
						  // nombrepoblacion, codpostal, …
riahc3 50 Â Team Colleague

Id like to post the code but its in spanish so it wouldnt help much.

I tried just making a typedef with a *cl but the problem is I cant go thru each 999 of the clients (c[num]). What Id like to do is point the *cl pointer to c[num] and somehow run thru it such as *cl[num] (I know a array is already a pointer so it wont work.)

If there is any part that I could describe so someone can help me, just say.

riahc3 50 Â Team Colleague

Hey everyone. Glad to become part of this community and I hope I continue to come here for a long time seeing as this site gives great helps. My problem:

I have a struct that is (for example) the following:

#define NUM 999

struct client
		{
                        int id;
			char name[15]; 
			char lastname[15]; 
			int telephone; 
}c[NUM];

I want to do the following: First I want to see if the file exists or not. Thats pretty simple using a pointer to the fopen function with the file; If it returns NULL it doesnt exist. Now the hard part is reading and loading and then after saving.

If it isnt found, all the struct will be set to the number/string 0. If its found, then all of the data from the text file is loaded onto the struct and I work with the struct modifing, deleteing, adding, etc.
At the end of the program when I hit enter, Id like for the program to save all (or the changes) to the text file so when I load the program again it has all the additions I previously made.

If Im not clear on something, go ahead and ask. Thank you very much for your help.