Thread: Change string inside the function

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    15

    Change string inside the function

    II need to enter a string and receive the same changed string.

    Code:
     #include <stdio.h>
    #include <string.h>
    
    
    char *lerdados(char txt[100],char *ler);
    
    int main ( )
    {
    
    char str[100]="casa";
    char *lerval;
    
    lerval=&str;
    
    lerdados(str,lerval);
    
    printf("%s)",lerdados );
    
    
    }
    
    //pass a string to function and return the value changed 
    char *lerdados(char txt[100],char *ler)
    {
    
    char *pont;
    pont=ler;
    
    
    printf("%s)",ler );
    
       scanf("%s", pont);
    
       return *pont;
    }
    Why does not this work?
    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    How many warnings did you get when you tried to compile it? You should have got several.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2016, 06:24 PM
  2. assign string to the string variable inside structure!
    By king_zart in forum C++ Programming
    Replies: 20
    Last Post: 12-09-2012, 11:37 AM
  3. Replies: 3
    Last Post: 01-15-2012, 06:09 AM
  4. how to change and return a string from function?
    By cywong18 in forum C Programming
    Replies: 8
    Last Post: 03-23-2002, 08:24 AM
  5. Replies: 4
    Last Post: 01-22-2002, 11:13 PM

Tags for this Thread