برنامه ای که نحوه عملکرد تابع strncpy را نشان میدهد:

#include <iostream.h>
#include <cstring.h>

int main(){
  char str[ ] = "cats are nice usually.";
    cout<<"before operating :\n"<<str;
     strncpy(str,"dogs",4);
      strncpy(str+9,"mean",4);
        cout<<"\nafter operating :\n"<<str<<endl;
  return 0 ;
}

//end