Returnin value (processed)

Hi

I was studying the simpliest code to return the value to the main function from the other function.

I want to type "ABCDE" and want to print it out in the [b]trim function[/b] and in the [b]main function[/b] as a return value from the [b]trim function[/b].

[code]

#include

void trim (char charArray[]){
int* trimmed[5];

//just to see if I could pass the string to this function from main
printf("This is in the trim function, the data entered are:
"
"%s
", charArray);

//copy the content of charArray to trimmed just to see...
*trimmed = *charArray;

//if I can return trimmed, instead of charArray
return *trimmed;

}/*end trim*/

int main(){
char data[5];

printf("Enter a line:");
gets(data);
trim(data);

//then, I want to see if *trimmed will return the same
printf("This is the main:%s
", data);

system("PAUSE");

}/*end main*/
[/code]

In the [b]trim function[/b], I did not do anything to the string passed from the main on purpose. I just want to see how I can return the string back to the main function by using another variable(?) in case if I process something on the original [b]charArray[/b].

But, actually, I think.. the following part is doing nothing...?
[code]
*trimmed = *charArray;

return *trimmed;
[/code]


Could anyone advise how to return *trimme (or trimme) value to the main!!



(I once posted the similar question with more complicated coding..


cheers!

Comments

  • : Hi
    :
    : I was studying the simpliest code to return the value to the main function from the other function.
    :
    : I want to type "ABCDE" and want to print it out in the [b]trim function[/b] and in the [b]main function[/b] as a return value from the [b]trim function[/b].
    :
    : [code]
    :
    : #include
    :
    : void trim (char charArray[]){
    : int* trimmed[5];
    :
    : //just to see if I could pass the string to this function from main
    : printf("This is in the trim function, the data entered are:
    "
    : "%s
    ", charArray);
    :
    : //copy the content of charArray to trimmed just to see...
    : *trimmed = *charArray;
    :
    : //if I can return trimmed, instead of charArray
    : return *trimmed;
    :
    : }/*end trim*/
    :
    : int main(){
    : char data[5];
    :
    : printf("Enter a line:");
    : gets(data);
    : trim(data);
    :
    : //then, I want to see if *trimmed will return the same
    : printf("This is the main:%s
    ", data);
    :
    : system("PAUSE");
    :
    : }/*end main*/
    : [/code]
    :
    : In the [b]trim function[/b], I did not do anything to the string passed from the main on purpose. I just want to see how I can return the string back to the main function by using another variable(?) in case if I process something on the original [b]charArray[/b].
    :
    : But, actually, I think.. the following part is doing nothing...?
    : [code]
    : *trimmed = *charArray;
    :
    : return *trimmed;
    : [/code]
    :
    :
    : Could anyone advise how to return *trimme (or trimme) value to the main!!
    :
    :
    :
    : (I once posted the similar question with more complicated coding..
    :
    :
    : cheers!
    :



    Well, that was confusing... I'll try to give a general explanation about how to pass arrays and pointers.

    First thing you need to know is that you can't pass a whole array as a parameter in C. This is good, because there is never a reason to do so, and passing a whole array would take up loads of stack memory. Instead you pass a pointer to the array. This means that no copy of the array is made, the function will work with the array that is allocated by the caller (main in this case).

    Because it has a pointer to the array's address, the function may change the contents of that array. Therefore, any change done to the array by the function will remain when the function is finished.

    This is different from passing parameters by value. A function like this would do nothing:

    [code]void func (char x)
    {
    x = 5;
    }

    int main()
    {
    char ch = 3;
    func(ch);
    }
    [/code]

    Because x is a -copy- of the value in main, passed to the function.
    If you passed it by reference however, it would change the value in main:

    [code]void func (char* x)
    {
    *x = 5;
    }

    int main()
    {
    char ch = 3;
    func(&ch);
    }
    [/code]


    Arrays work in the same way, but when you use them, you don't have the option to pass them by value.



    Returning pointers:

    If you wish, you could re-write the function above as

    [code]char* func2 (char* x)
    {
    *x = 5;
    return x;
    }[/code]

    But it is pretty pointless - all it does is to return a copy of the pointer.

    What you -never- can do is to return a pointer to a local variable in the function. You will get a pointer to a memory area that has ceased to exist:

    [code]
    char* badFunc (char* x)
    {
    char ch;
    ch = *x + 5;
    return &ch; /* NOT ALLOWED! */
    }
    [/code]

    In almost every case, returning a pointer is a bad idea. I never do it in my programs, but there are probably people that won't agree with me on that, sence it is a matter of coding style.

    (As a side-note for those people: no, dynamic allocation from inside the function is not a good example of when it should be done. All allocation should be handled by the caller if possible, to avoid memory leaks.)
  • : Hi
    :
    : I was studying the simpliest code to return the value to the main function from the other function.
    :
    : I want to type "ABCDE" and want to print it out in the [b]trim function[/b] and in the [b]main function[/b] as a return value from the [b]trim function[/b].
    :
    : [code]
    :
    : #include
    :
    : void trim (char charArray[]){
    : int* trimmed[5];
    :
    : //just to see if I could pass the string to this function from main
    : printf("This is in the trim function, the data entered are:
    "
    : "%s
    ", charArray);
    :
    : //copy the content of charArray to trimmed just to see...
    : *trimmed = *charArray;
    :
    : //if I can return trimmed, instead of charArray
    : return *trimmed;
    :
    : }/*end trim*/
    :
    : int main(){
    : char data[5];
    :
    : printf("Enter a line:");
    : gets(data);
    : trim(data);
    :
    : //then, I want to see if *trimmed will return the same
    : printf("This is the main:%s
    ", data);
    :
    : system("PAUSE");
    :
    : }/*end main*/
    : [/code]
    :
    : In the [b]trim function[/b], I did not do anything to the string passed from the main on purpose. I just want to see how I can return the string back to the main function by using another variable(?) in case if I process something on the original [b]charArray[/b].
    :
    : But, actually, I think.. the following part is doing nothing...?
    : [code]
    : *trimmed = *charArray;
    :
    : return *trimmed;
    : [/code]
    :
    :
    : Could anyone advise how to return *trimme (or trimme) value to the main!!
    :
    :
    :
    : (I once posted the similar question with more complicated coding..
    :
    :
    : cheers!
    :


    *trimmed = *charArray doesn't work, at least it doesn't copy the whole array, for its an array, not a single variable

    to copy data from one array to another, you'll need to use the library function strcpy(), the first agrument is the string to recieve the new data, and the second is the one copied. If the size of the second is greater than the first, then you'll have an overrun error, so be careful.

    To use strcpy, you need to include string.h

    then again, in your example, the array you return is a local variable, so it'll be destroyed after the function returns, so an error will result in runtime if you try to access the returned array.

    To return an array that won't be destroyed, you need to use dynamic memory allocation...you remember this, have you gone over it yet?

    {2}rIng
  • [b][red]This message was edited by tokoG at 2006-3-7 0:6:9[/red][/b][hr]
    Hi, Lundin and Gregry
    :
    : First thing you need to know is that you can't pass a whole array as a parameter in C. This is good, because there is never a reason to do so, and passing a whole array would take up loads of stack memory.

    [blue]
    How about in the case of
    [b]int func (char charArray[])[/b]? In this kind of prototype, is this [b]passing a whole array[/b]?
    [/blue]

    Instead you pass a pointer to the array. This means that no copy of the array is made, the function will work with the array that is allocated by the caller (main in this case).

    [blue]
    Actually... I didn't need to point the charArray[]...
    But are you saying if in the case of [b]*charArray[][/b], this could be a parameter but not [b]charArray[][/b][/blue]?


    :
    : Because it has a pointer to the array's address, the function may change the contents of that array. Therefore, any change done to the array by the function will remain when the function is finished.

    [blue]
    Does it mean, if I want to change the content of the array in the function, should I make the function parameter with *? like,
    [b]void func (char* charArray[])[/b]
    [/blue]


    : This is different from passing parameters by value. A function like this would do nothing:
    :
    : [code]void func (char x)
    : {
    : x = 5;
    : }
    :
    : int main()
    : {
    : char ch = 3;
    : func(ch);
    : }
    : [/code]

    [blue]
    Noted.
    [/blue]


    :
    : Because x is a -copy- of the value in main, passed to the function.
    : If you passed it by reference however, it would change the value in main:
    :
    : [code]void func (char* x)
    : {
    : *x = 5;
    : }
    :
    : int main()
    : {
    : char ch = 3;
    : func(&ch);
    : }
    : [/code]
    :
    :
    : Arrays work in the same way, but when you use them, you don't have the option to pass them by value.

    [blue]
    If you say, it works the same for array, since array is the pointer it self, I don't need [b]*[/b]? which means... array is already [b]de-referenced[/b] and [b]charArray[][/b] and [b]char* x[/b](variable)
    [/blue] with the pointer works the same?




    : Returning pointers:
    :
    : If you wish, you could re-write the function above as
    :
    : [code]char* func2 (char* x)
    : {
    : *x = 5;
    : return x;
    : }[/code]
    :
    : But it is pretty pointless - all it does is to return a copy of the pointer.

    [blue]
    Right.. b/c it reutns 5 (which x is pointing to) anyway.
    [/blue]


    :
    : What you -never- can do is to return a pointer to a local variable in the function. You will get a pointer to a memory area that has ceased to exist:
    :
    [blue]
    In this case, *trimmed = *charArray; means I was trying to returning a pointer to a local value, is it?
    [/blue]



    ---------------------------------
    I tried to simplify the trimming programme in the following code.
    I want to eliminate the char 'A' from the input read in the main function, pass it to the other function to eliminate, then pass back the eliminated value to the main.

    e.g) "ABC" were entered
    then, return only "BC"

    First, without using any pointer, I coded as follows.. but didn't work!!
    I also used [b]strcpy[/b] as Gregry advised in his reply of this thread.

    [code]
    //This doesn't work as expected. - see the output-
    //Works if I didn't process anything
    #include

    void trim (char charArray[]){

    int i = 0;
    char trimmed[5];

    printf("This is in the trim function, the data entered are:
    "
    "%s
    ", charArray);//to check what was passed to this function

    //[red]THIS DOESN'T WORK, WOULD YOU ADVISE HOW TO?[/red]
    for(i=0; i<5; i++){//try to eliminate 'A' from the entered "ABC"
    if(charArray[i] == 'A')//when 'A' is found, discard
    i++;
    }

    strcpy(trimmed, charArray); //copy the 'A'-discarded-charArray to trimmed to return to the main


    }/*end trim*/

    int main(){
    char data[5];

    printf("Enter a line for processing:");
    gets(data); //for example, enter "ABC",
    trim(data); //pass "ABC" to the function above,

    printf("This is back in main:%s
    ", data);

    getchar();//to pause the screen until ENTER to be pressed

    }/*end main*/
    [/code]

    ----output---- ---Expected output---
    Enter: ABC Enter: ABC
    In the func: ABC In the func: ABC
    Back in main: ABC Back in the main: BC
    ---------------- ---------------------

    [blue]
    I dont think.. I need to use a pointer in here,,, do I??
    To test my understanding of you guys's advices on the passing pointer, I have to code different programme to test. :p
    [/blue]


    [b][blue]
    PS: To Gregry;
    Dynamic Allocation, you mean to make the variable as global variable??
    [/blue][/b]








  • : [b][red]This message was edited by tokoG at 2006-3-7 0:6:9[/red][/b][hr]
    : Hi, Lundin and Gregry
    : :
    : : First thing you need to know is that you can't pass a whole array as a parameter in C. This is good, because there is never a reason to do so, and passing a whole array would take up loads of stack memory.
    :
    : [blue]
    : How about in the case of
    : [b]int func (char charArray[])[/b]? In this kind of prototype, is this [b]passing a whole array[/b]?
    : [/blue]

    [green]
    No, you -can't- pass a whole array. The above is a pointer as well, just with another syntax.
    [/green]


    :
    : Instead you pass a pointer to the array. This means that no copy of the array is made, the function will work with the array that is allocated by the caller (main in this case).
    :
    : [blue]
    : Actually... I didn't need to point the charArray[]...
    : But are you saying if in the case of [b]*charArray[][/b], this could be a parameter but not [b]charArray[][/b][/blue]?

    [green]
    No, charArray[] means that you got a pointer to an array.
    char *charArray[] means that you got a pointer to an array of pointers (2d array).
    [/green]

    :
    :
    : :
    : : Because it has a pointer to the array's address, the function may change the contents of that array. Therefore, any change done to the array by the function will remain when the function is finished.
    :
    : [blue]
    : Does it mean, if I want to change the content of the array in the function, should I make the function parameter with *? like,
    : [b]void func (char* charArray[])[/b]
    : [/blue]

    [green]No, you should write
    void func (char charArray[])
    [/green]


    :
    :
    : : This is different from passing parameters by value. A function like this would do nothing:
    : :
    : : [code]void func (char x)
    : : {
    : : x = 5;
    : : }
    : :
    : : int main()
    : : {
    : : char ch = 3;
    : : func(ch);
    : : }
    : : [/code]
    :
    : [blue]
    : Noted.
    : [/blue]
    :
    :
    : :
    : : Because x is a -copy- of the value in main, passed to the function.
    : : If you passed it by reference however, it would change the value in main:
    : :
    : : [code]void func (char* x)
    : : {
    : : *x = 5;
    : : }
    : :
    : : int main()
    : : {
    : : char ch = 3;
    : : func(&ch);
    : : }
    : : [/code]
    : :
    : :
    : : Arrays work in the same way, but when you use them, you don't have the option to pass them by value.
    :
    : [blue]
    : If you say, it works the same for array, since array is the pointer it self, I don't need [b]*[/b]? which means... array is already [b]de-referenced[/b] and [b]charArray[][/b] and [b]char* x[/b](variable)
    : [/blue] with the pointer works the same?

    [green]
    Yes. These two functions will work the same way:

    void func (char* array);
    void func (char array[]);
    [/green]

    :
    :
    :
    :
    : : Returning pointers:
    : :
    : : If you wish, you could re-write the function above as
    : :
    : : [code]char* func2 (char* x)
    : : {
    : : *x = 5;
    : : return x;
    : : }[/code]
    : :
    : : But it is pretty pointless - all it does is to return a copy of the pointer.
    :
    : [blue]
    : Right.. b/c it reutns 5 (which x is pointing to) anyway.
    : [/blue]

    [green]
    Yes, because all it does is to copy the pointer. You could as well have a function like
    void func (char* x) that changes x. Then in main you could make the copy, if you need one:

    char something[10];
    char* ptr;

    func(something);
    ptr = something;

    [/green]


    :
    : :
    : : What you -never- can do is to return a pointer to a local variable in the function. You will get a pointer to a memory area that has ceased to exist:
    : :
    : [blue]
    : In this case, *trimmed = *charArray; means I was trying to returning a pointer to a local value, is it?
    : [/blue]

    [green]
    Your function did not have any return type... but if it had and you changed the contents of trimmed, you should not return a pointer to it.
    [/green]

    :
    :
    :
    : ---------------------------------
    : I tried to simplify the trimming programme in the following code.
    : I want to eliminate the char 'A' from the input read in the main function, pass it to the other function to eliminate, then pass back the eliminated value to the main.
    :
    : e.g) "ABC" were entered
    : then, return only "BC"
    :
    : First, without using any pointer, I coded as follows.. but didn't work!!
    : I also used [b]strcpy[/b] as Gregry advised in his reply of this thread.
    :
    : [code]
    : //This doesn't work as expected. - see the output-
    : //Works if I didn't process anything
    : #include
    :
    : void trim (char charArray[]){
    :
    : int i = 0;
    : char trimmed[5];
    :
    : printf("This is in the trim function, the data entered are:
    "
    : "%s
    ", charArray);//to check what was passed to this function
    :
    : //[red]THIS DOESN'T WORK, WOULD YOU ADVISE HOW TO?[/red]
    : for(i=0; i<5; i++){//try to eliminate 'A' from the entered "ABC"
    : if(charArray[i] == 'A')//when 'A' is found, discard
    : i++;
    : }
    :
    : strcpy(trimmed, charArray); //copy the 'A'-discarded-charArray to trimmed to return to the main
    :
    :
    : }/*end trim*/
    :
    : int main(){
    : char data[5];
    :
    : printf("Enter a line for processing:");
    : gets(data); //for example, enter "ABC",
    : trim(data); //pass "ABC" to the function above,
    :
    : printf("This is back in main:%s
    ", data);
    :
    : getchar();//to pause the screen until ENTER to be pressed
    :
    : }/*end main*/
    : [/code]
    :
    : ----output---- ---Expected output---
    : Enter: ABC Enter: ABC
    : In the func: ABC In the func: ABC
    : Back in main: ABC Back in the main: BC
    : ---------------- ---------------------
    :
    : [blue]
    : I dont think.. I need to use a pointer in here,,, do I??
    : To test my understanding of you guys's advices on the passing pointer, I have to code different programme to test. :p
    : [/blue]

    [green]
    That function does nothing, sence in order to change anything, you must change the charArray. Inside the for-loop, copy the letter to "trimmed" unless it is 'A'. Note that "i" will keep track of the current index in "charArray", but it will not keep track of the index in "trimmed". So one way of solving it is to add another counter like "i", which you only increase every time you copy a letter.

    When "trimmed" is finished, use strcpy(charArray, trimmed) to get the result back to main, [italic]through[/italic] "charArray", meaning that whatever was inside charArray is now lost.
    [/green]

    :
    :
    : [b][blue]
    : PS: To Gregry;
    : Dynamic Allocation, you mean to make the variable as global variable??
    : [/blue][/b]

    [green]Nope, it is not what he means. Nevermind dynamic allocation until you have complete understanding about pointers.
    [/green]
  • [b][red]This message was edited by tokoG at 2006-3-7 5:5:18[/red][/b][hr]
    : : [blue]
    : : If you say, it works the same for array, since array is the pointer it self, I don't need [b]*[/b]? which means... array is already [b]de-referenced[/b] and [b]charArray[][/b] and [b]char* x[/b](variable)
    : : [/blue] with the pointer works the same?
    :
    : [green]
    : Yes. These two functions will work the same way:
    :
    : void func (char* array);
    : void func (char array[]);
    : [/green]

    NOTED

    : : [blue]
    : : In this case, *trimmed = *charArray; means I was trying to returning a pointer to a local value, is it?
    : : [/blue]
    :
    : [green]
    : Your function did not have any return type... but if it had and you changed the contents of trimmed, you should not return a pointer to it.
    : [/green]

    OK, noted

    : [green]
    : That function does nothing, sence in order to change anything, you must change the charArray. Inside the for-loop, copy the letter to "trimmed" unless it is 'A'. Note that "i" will keep track of the current index in "charArray", but it will not keep track of the index in "trimmed". So one way of solving it is to add another counter like "i", which you only increase every time you copy a letter.
    :
    : When "trimmed" is finished, use strcpy(charArray, trimmed) to get the result back to main, [italic]through[/italic] "charArray", meaning that whatever was inside charArray is now lost.
    : [/green]
    :

    GRRR, I can't get it work!!
    I coded as followed and tried i++, trimmed++ etc.. but can;t get it work. One more time, can you pls advise how to get this work?

    [code]
    #include

    void main(){
    int i;
    char charArray[5];
    char trimmed[5];


    printf("Enter a text in charArray: ");
    scanf("%s", &charArray);//For example, enter "CBA"

    for(i=0; charArray[i] != ''; i++){
    if(charArray[i] == 'A')//If 'A', keep it in trimmed[i],
    trimmed[i] = charArray[i];
    else {//if not 'B', then discard

    /*Tried with i++, trimmed++, charArray++... didn't work*/

    }/*end else*/

    }/*end for*/


    printf("
    Trimmed with only A: %s
    ", trimmed);

    fflush(stdin);
    getchar();

    }/*end main*/
    [/code]

    It works without [b]e[/b] if I enter [b]"ABC"[/b], I get the output [b]"A"[/b] because 'A' was entered first.
    But, not when I enter "CBA", I get nothing on the output....sob


    : : [b][blue]
    : : PS: To Gregry;
    : : Dynamic Allocation, you mean to make the variable as global variable??
    : : [/blue][/b]
    :
    : [green]Nope, it is not what he means. Nevermind dynamic allocation until you have complete understanding about pointers.
    : [/green]

    OK, I will remember the word of it and will learn when I come across. ;)



  • [b][red]This message was edited by Lundin at 2006-3-7 5:21:24[/red][/b][hr]
    [code]
    /* version using counters */

    #include
    #include

    int main()
    {
    int i;
    int j;
    char charArray[5];
    char trimmed[5];

    printf("Enter a text in charArray: ");
    scanf("%s", charArray);/*For example, enter "CBA"*/
    getchar();

    j=0;
    for(i=0; i
    #include

    int main()
    {
    char charArray[5];
    char trimmed[5];
    char* char_p;
    char *trim_p;

    printf("Enter a text in charArray: ");
    scanf("%s", charArray);/*For example, enter "CBA"*/
    getchar();

    trim_p = trimmed;
    for(char_p=charArray; *char_p != ''; char_p++)
    {
    if(*char_p == 'A')/*If 'A', keep it in trimmed[i],*/
    {
    *trim_p = *char_p;
    trim_p++;
    }
    }/*end for*/
    *trim_p = ''; /* very important! */

    printf("
    Trimmed with only A: %s
    ", trimmed);
    getchar();

    }/*end main*/
    [/code]


  • Hi Lundin

    Thank you so much for your two codes explaning to code [b]with[/b] the pointer and [b]without[/b]. It's very very much lucid and very good explanation for me who's confused of the use of the pointer.

    I changed, modified and made couple of other codes based on yours. The one with passing the buffer and the other is passing buffer with pointer. Both worked fine!!! Yahoo!!!!!

    [b][red]trimmed[j] = '' /*very important*/[/b][/red]

    Noted. And I think this will make [b]trimmed[j][/b] a string to return to the main, isnt it? That's why it's important you said?

    I have one question though.
    You coded as follows for the user entery of the alphabets;

    [b]getchar();[/b]

    [code]
    printf("Enter a text in charArray: ");
    scanf("%s", charArray);/*For example, enter "CBA"*/
    getchar();
    [/code]

    Without [b]getchar();[/b], the output has strange characters.
    But, why is that?? I know the use of the getchar(); is to let the user press ENTER to quit the programme. But in here, it's placed [red]after[/red] the scanf.

    Thank you!
    tg

  • : [b]getchar();[/b]
    :
    : [code]
    : printf("Enter a text in charArray: ");
    : scanf("%s", charArray);/*For example, enter "CBA"*/
    : getchar();
    : [/code]
    :
    : Without [b]getchar();[/b], the output has strange characters.
    : But, why is that?? I know the use of the getchar(); is to let the user press ENTER to quit the programme. But in here, it's placed [red]after[/red] the scanf.
    :

    or, to get the char value like,

    [b]text = getchar();[/b]

    This is also the equivalent to,

    [b]scanf("%c
    ", text);[/b]

    ja?



    :

  • : Hi Lundin
    :
    : Thank you so much for your two codes explaning to code [b]with[/b] the pointer and [b]without[/b]. It's very very much lucid and very good explanation for me who's confused of the use of the pointer.
    :
    : I changed, modified and made couple of other codes based on yours. The one with passing the buffer and the other is passing buffer with pointer. Both worked fine!!! Yahoo!!!!!
    :
    : [b][red]trimmed[j] = '' /*very important*/[/b][/red]
    :
    : Noted. And I think this will make [b]trimmed[j][/b] a string to return to the main, isnt it? That's why it's important you said?

    [blue]Yes. Without the null termination it will only be an array of characters and not a string. You need it to be able to use the variable in string handling functions like strlen, strcmp, printf("%s",...) and so on.[/blue]

    : I have one question though.
    : You coded as follows for the user entery of the alphabets;
    :
    : [b]getchar();[/b]
    :
    : [code]
    : printf("Enter a text in charArray: ");
    : scanf("%s", charArray);/*For example, enter "CBA"*/
    : getchar();
    : [/code]
    :
    : Without [b]getchar();[/b], the output has strange characters.
    : But, why is that?? I know the use of the getchar(); is to let the user press ENTER to quit the programme. But in here, it's placed [red]after[/red] the scanf.
    :
    : Thank you!
    : tg
    :

    [blue]It eats the extra linefeed from the input buffer. Sence I ignore the return value, the linefeed will not be copied to a variable (there is no use for it). I added it to not change the original code too much.

    The serious way to get user input in a console application is by using fgets() and only that function. scanf() and gets() are to be concidered as debugging functions you use when leaning how to program.
    Details here: http://c-faq.com/stdio/scanfprobs.html
    [/blue]


  • :
    : [blue]It eats the extra linefeed from the input buffer. Sence I ignore the return value, the linefeed will not be copied to a variable (there is no use for it). I added it to not change the original code too much.
    :
    : The serious way to get user input in a console application is by using fgets() and only that function. scanf() and gets() are to be concidered as debugging functions you use when leaning how to program.
    : Details here: http://c-faq.com/stdio/scanfprobs.html
    : [/blue]
    :
    :

    Hi Lundin

    Thanks for the explanation of the use of the getchar() and the potential problem with using scanf(). I am learning fscanf part now as we are learning the I/O from other files.

    Also, thanks for the web page. Time to time, I will read it and study.

    :)

    cheers

    PS: By the way, about the assignment of the trimming spaces. Finally, I made it work and submitted! Thanks for all your help.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories