elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Limpiar columna en matriz de dos dimensiones en: 10 Septiembre 2015, 04:57 am
Hola,
tengo esta espina hace más de medio año, ojalá me puedan ayudar a comprender el tema.
No comprendo como es que funciona la siguiente linea:

Código:
(*p)[i] = 0;

comprendida en el siguiente código:

Código:
int mat[num_filas][num_columnas], (*p)[num_columnas], i; 
for(p = &mat[0]; p < &mat[num_filas]; p++)
(*p)[i] = 0;

Según mi libro, este for limpia la columna i de la matriz. Entiendo que p es un puntero a un array de enteros de tamaño num_columnas. Entiendo que en el for le asigna la primera fila de la matriz al puntero, comprueba que sea menor o igual a la ultima fila, y aumenta p de fila en fila. Y entiendo que en
Código:
(*p)[i] = 0;
la i es la columna a rellenar con 0, pero lo que me confunde es el uso del valor al que apunta p, es decir (*p) con un subíndice. Además en mi libro dice que los paréntesis de (*p) son necesarios ya que sino el compilador interpretaría *(p), lo cual sí que tiene sentido para mi.
2  Programación / Programación C/C++ / Problema con while en C en: 4 Mayo 2014, 06:29 am
Hola estoy empezando a programar en C y estoy con un ejercicio de calculo de promedio de unas calificaciones con while que a mi entender deberia funcionar pero no lo hace! Aqui esta mi codigo
Código:
//3.8 CLASS AVERAGE PROGRAM WITH SENTINEL CONTROLLED REPETITION
#include <stdio.h>

int main (void)
{
    int counter;//number of grades entered
    int grade;//grades value
    int total;//sum of grades
    float average;//average

    //initialization phase
    total = 0;
    counter = 0;
    grade = 0;

    //processing phase
    while( grade != -1) {
        puts( "Please type the grade and press enter. To finish type \"-1\"." );//asks user to type a grade
        scanf( "%d", &grade );//stores the grade typed by the user into the grade variable
        total = total + grade;//adds the grade typed by the user to the total
        counter = counter + 1;//adds one to the counter
    }//end while

    //termination phase
    //if counter is not equal to zero, calculate the average and print it, if not print "No grades were entered"
    if( counter != 0){
        average = ( float ) total / counter;
        printf( "Average is %.2f\n", average );
    }//end if
    else{
        puts( "No grades were entered" );
    }//end else
}//end main

y aqui esta el codigo que funciona, pero me gustaría entender por que el mio no lo hace:
Código:
//3.8 CLASS AVERAGE PROGRAM WITH SENTINEL CONTROLLED REPETITION
#include <stdio.h>

int main (void)
{
    int counter;//number of grades entered
    int grade;//grades value
    int total;//sum of grades
    float average;//average

    //initialization phase
    total = 0;
    counter = 0;

    //processing phase
        puts( "Please type the grade and press enter. To finish type \"-1\"." );//asks user to type a grade
        scanf( "%d", &grade );//stores the grade typed by the user into the grade variable

    while( grade != -1) {
        total = total + grade;//adds the grade typed by the user to the total
        counter = counter + 1;//adds one to the counter
        puts( "Please type the grade and press enter. To finish type \"-1\"." );//asks user to type a grade
        scanf( "%d", &grade );//stores the grade typed by the user into the grade variable

    }//end while

    //termination phase
    //if counter is not equal to zero, calculate the average and print it, if not print "No grades were entered"
    if( counter != 0){
        average = ( float ) total / counter;
        printf( "Average is %.2f\n", average );
    }//end if
    else{
        puts( "No grades were entered" );
    }//end else
}//end main

Desde ya MUCHAS GRACIAS!
3  Programación / Programación C/C++ / ¿Cuál es la diferencia entre el preprocesador y el enlazador en C? en: 2 Mayo 2014, 22:32 pm
Estoy confundido ya que pareciera ser que ambos hacen ¿lo mismo? incluyen información en nuestro archivo para poder ejecutar las funciones? (El preprocesador con #include) Excepto que uno lo hace antes de la compilación y otro lo hace después. AYUDA
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines