Advertisement
Guest User

Untitled

a guest
Nov 8th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main(int argc,char* argv[]){
  5.  
  6.      printf("Adj meg egy tetszoleges stringet:");
  7.        char* s=malloc(1);s[0]=0;/* stirng inicializalas*/
  8.       {/* stirng beolvasas
  9.                meret elore nem ismert*/
  10.        int meret=1;
  11.        char c;
  12.        while ((c=getchar())!='\n'){
  13.          meret++;
  14.          s=(char*)realloc(s,meret);/*lefoglat memoria dinamikus novelese*/
  15.          s[meret-2]=c;
  16.          s[meret-1]=0;/*string vegjel*/
  17.         }          
  18.       }
  19.  printf("A(z) %s stringet adtad meg.",s);
  20.  return 0;   
  21. }
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement