Hack Forums
[C] function in c fill a table - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] function in c fill a table (/showthread.php?tid=6131881)



function in c fill a table - blackcoder00 - Jan 6, 2021

i have some problem i couldn't fill some data in a table it's like an infinity loop


PHP Code

<?php 
#include <stdio.h>
#include <stdlib.h>

void saisie (int n){
printf("donner n : \n");
scanf("\n %i",&n);



}

void remplire(int * t,int n){

for(
int i = 0 ;i<n;i++){

    
printf("donner t[%i]",i);
    
scanf("\n %i",&t[i]);
}


}


void affiche (int * t,int n){
for (
int i = 0 ;i < n ;i++){
    
printf("%d",t[i]);

}

}



 
main(){
int n;
int t[20];
saisie(n);
remplire(t,n);
affiche(t,n);

} 



RE: function in c fill a table - HFDone - Jan 6, 2021

you didnt gave value for > int n
int n = 10;


RE: function in c fill a table - blackcoder00 - Jan 6, 2021

(Jan 6, 2021 01:16 PM)HFDone Wrote:  you didnt gave value for > int n
int n = 10;

i will give it with the void saisie
PHP Code

<?php 
void saisie 
(int * n){
printf("donner n : \n");
scanf("%i",&n);



} 



RE: function in c fill a table - HFDone - Jan 6, 2021

main(){
int n = 20;
int t[20];
saisie(n);
remplire(t,n);
affiche(t,n);
return 0;
}


RE: function in c fill a table - Tafelpoot - Jan 6, 2021

as HFdone mentioned you have not initialized your int n;


RE: function in c fill a table - Juice - Jan 19, 2021

This looks very complicated... very complex.... very intricate.


RE: function in c fill a table - Inveil - Jan 26, 2021

I need help with this too


RE: function in c fill a table - blackcoder00 - Jan 27, 2021

(Jan 26, 2021 05:36 PM)Inveil Wrote:  I need help with this too

pm me


RE: function in c fill a table - TaZeer - Jan 30, 2021

(Jan 6, 2021 12:43 PM)blackcoder00 Wrote:  i have some problem i couldn't fill some data in a table it's like an infinity loop


PHP Code

<?php 
#include <stdio.h>
#include <stdlib.h>

void saisie (int n){
printf("donner n : \n");
scanf("\n %i",&n);



}

void remplire(int * t,int n){

for(
int i = 0 ;i<n;i++){

    printf("donner t[%i]",i);
    scanf("\n %i",&t[i]);
}


}


void affiche (int * t,int n){
for (
int i = 0 ;i < n ;i++){
    printf("%d",t[i]);

}

}



 
main(){
int n;
int t[20];
saisie(n);
remplire(t,n);
affiche(t,n);

} 

Use *int on your function saisie to modify the 'n' value


RE: function in c fill a table - saltycracker - Jan 30, 2021

Wow! I haven't programmed in C in years but I can see that you are lacking even the most fundamental understanding of the language.

Example.. What is the function supposed to do? It makes no sense?

Code
void saisie (int n){
  printf("donner n : \n");
  scanf("\n %i",&n);
}

The way you have it written.You have a function which accepts an integer and then you overwrite that integer via scanf and then throw the value away.