Thread: system function

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    6

    system function

    I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
    The program is as follows:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void){
    
    char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
    
    printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
    scanf("%75s", hostfile);
    
    printf("Enter the path(with name and extension of the file) to the file you want to hide: ");
    scanf("%75s", hiddenfile);
    
    printf("Enter the name of the file you want to hide: ");
    scanf("%15s", hiddenFileName);
    
     system("type \"%s\" > \"%s:%s\"", hiddenfile, hostfile, hiddenFileName);
    return 0;
    }
    The complier is showing error as "Extra Perimeter in call to system"
    but I am not getting where?
    Last edited by Khokhar; 04-05-2013 at 02:20 AM.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Code:
    system("type \"%s\" > \"%s:%s\"", hiddenfile, hostfile, hiddenFileName);
    system() only takes one argument, a pointer to char.

    You need to construct your string before calling system(), e.g. using sprintf().

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    Now I changed the code and its isn't working now also.
    Here is the code:
    Code:
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. int hide_file(char *host, char *hidden, char *name);
    4. int show_file(char *hostfile, char *filename);
    5. int main(void){
    6. char hostfile[75], hiddenfile[75], hiddenFileName[15];
    7. int status1, status2;
    8. printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
    9. scanf("%75s", hostfile);
    10. printf("Enter the path(with name and extension of the file) to the file you want to hide: ");
    11. scanf("%75s", hiddenfile);
    12. printf("Enter the name of the file you want to hide: ");
    13. scanf("%15s", hiddenFileName);
    14. status1 = hide_file(hostfile, hiddenfile, hiddenFileName);
    15. if (status1 == 0) {
    16. printf("Stream created and file is hidden. \n");
    17. status2 = show_file(hostfile, hiddenFileName);
    18. } else{
    19. printf("Something went wrong");
    20. }
    21. getchar();
    22. getchar();
    23. return 0;
    24. }
    25. int hide_file(char *host, char *hidden, char *name){
    26. int status = 0;
    27. char everything[150];
    28. sprintf(everything, "type \"%s\" > \"%s:%s\"", hidden, host, name);
    29. status = system(everything);
    30. return status;
    31. }
    32. int show_file(char *hostfile, char *filename){
    33. int status_2 = 0;
    34. char see_hidden[150];
    35. sprintf(see_hidden ,"notepad %s:%s",hostfile, filename );
    36. status_2 = system(see_hidden);
    37. return status_2;
    38. }

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    6
    Now I changed the code and its isn't working now also.
    Here is the code:
    Code:
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. int hide_file(char *host, char *hidden, char *name);
    4. int show_file(char *hostfile, char *filename);
    5. int main(void){
    6. char hostfile[75], hiddenfile[75], hiddenFileName[15];
    7. int status1, status2;
    8. printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
    9. scanf("%75s", hostfile);
    10. printf("Enter the path(with name and extension of the file) to the file you want to hide: ");
    11. scanf("%75s", hiddenfile);
    12. printf("Enter the name of the file you want to hide: ");
    13. scanf("%15s", hiddenFileName);
    14. status1 = hide_file(hostfile, hiddenfile, hiddenFileName);
    15. if (status1 == 0) {
    16. printf("Stream created and file is hidden. \n");
    17. status2 = show_file(hostfile, hiddenFileName);
    18. } else{
    19. printf("Something went wrong");
    20. }
    21. getchar();
    22. getchar();
    23. return 0;
    24. }
    25. int hide_file(char *host, char *hidden, char *name){
    26. int status = 0;
    27. char everything[150];
    28. sprintf(everything, "type \"%s\" > \"%s:%s\"", hidden, host, name);
    29. status = system(everything);
    30. return status;
    31. }
    32. int show_file(char *hostfile, char *filename){
    33. int status_2 = 0;
    34. char see_hidden[150];
    35. sprintf(see_hidden ,"notepad %s:%s",hostfile, filename );
    36. status_2 = system(see_hidden);
    37. return status_2;
    38. }

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    "It isn't working" is not a problem description.

    And please post your code simply as plain text without leading line numbers.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C system(...) function
    By achitan in forum C Programming
    Replies: 10
    Last Post: 01-27-2011, 02:36 PM
  2. Help with system() function
    By anju.kap2r in forum C Programming
    Replies: 8
    Last Post: 03-24-2009, 11:20 AM
  3. system() function using
    By Rommeo in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2007, 10:57 AM
  4. system() function.
    By Munkey01 in forum C++ Programming
    Replies: 3
    Last Post: 12-24-2002, 03:15 PM
  5. System Function
    By neva4getme in forum C Programming
    Replies: 1
    Last Post: 04-18-2002, 09:20 AM