Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22039

Routine with Do While and For make a unknow error GCC Core dump (Segment fault)

$
0
0

After compiling this program with GCC (Linux or Windows or online test compiler), it fails in different ways each time it runs. I don't understand where I made the mistake.

On Ubuntu Linux, the program crashes without printing an answer.

On Windows 10 (MSYS), it loops indefinitely without printing any message.

On an online compiler I tried, it fails with a segmentation fault (and core dump and exit code 139).

Here is the code:

#include <stdio.h>int main() {  float riga[1][3];  int ciclo = 2;  int calcolo;  float totale;  int codice = 0;  int quanti = 1;  int prezzo = 2;  printf("\n Inserendo una quantita pari a 0 si conclude con il totale");  do {    codice++;    printf("\n Numero: %d Inserire la quantita:", codice);    scanf("%f", &riga[codice][quanti]);    if ( riga[codice][quanti] < 1 ){      printf("\n Calcolo del totale.");      ciclo = 1;    } else {      printf("\n Numero: %d Inserire il prezzo:", codice);      scanf("%f", &riga[codice][prezzo]);    }    //printf("\n Quantita: %f Prezzo: %f", riga[codice -1][quanti], riga[codice -1 ][prezzo]);    //printf("\n Ciclo = %d", ciclo);  } while( ciclo != 1 );  printf("\n Totale in calcolo");  for ( calcolo = 1; calcolo < (codice + 1); calcolo++){    //printf("\n Prezzo = %f",riga[calcolo][prezzo] );    totale = totale + (riga[calcolo][prezzo] * riga[calcolo][quanti]);    }  printf("\n Totale: %f", totale);  return 0;}

What is wrong with it?


Viewing all articles
Browse latest Browse all 22039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>