| | |
Problem in Renaming of file???
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 294
Reputation:
Solved Threads: 11
I want to rename file with name of ip address like (192.168.1.55.txt)
In xyz.txt file have ip address.
I m finding this ip address but rename giving problem???
This gives OutPut:->
Before Rename 192.168.1.55
Error renaming file: Permission denied
How to solve this problem ??
In xyz.txt file have ip address.
I m finding this ip address but rename giving problem???
c Syntax (Toggle Plain Text)
#include <stdio.h> #include<conio.h> int main () { int result; char ipadd[20]; FILE *pFile;; pFile = fopen ("xyz.txt" , "r"); fseek(pFile,172,SEEK_SET); fgets (ipadd , 16 , pFile); printf("Before Rename"); printf("%s",ipadd); // it gives ip address in xyz.txt char oldname[] ="xyz.txt"; result= rename( oldname , ipadd ); //problem is here if ( result == 0 ) puts ( "File successfully renamed" ); else perror( "Error renaming file" ); fclose (pFile); getch(); }
Before Rename 192.168.1.55
Error renaming file: Permission denied
How to solve this problem ??
Last edited by Ancient Dragon; May 3rd, 2008 at 7:56 am. Reason: add code tags
•
•
Join Date: Apr 2008
Posts: 294
Reputation:
Solved Threads: 11
c Syntax (Toggle Plain Text)
#include <stdio.h> #include<conio.h> int main () { int result; char ipadd[20]; FILE *pFile;; pFile = fopen ("xyz.txt" , "r"); fseek(pFile,172,SEEK_SET); fgets (ipadd , 16 , pFile); fclose (pFile); printf("Before Rename"); printf("%s",ipadd); // it gives ip address in xyz.txt char oldname[] ="xyz.txt"; result= rename( oldname , ipadd ); //problem is here if ( result == 0 ) puts ( "File successfully renamed" ); else perror( "Error renaming file" ); getch(); }
Before Rename 192.168.1.55
Error renaming file: Invalid Argument
Last edited by Ancient Dragon; May 3rd, 2008 at 9:08 am. Reason: add code tags -- for the 2nd time
fgets() add the '\n' to the end of the string if it exists in the file. So you need to strip it off before calling rename().
C Syntax (Toggle Plain Text)
fgets (ipadd , 16 , pFile); if( ipadd[strlen(ipadd)-1] == '\n') ipadd[strlen(ipadd)-1] = 0;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
fseek is causing the problem.
Make sure to return a value from main.
Also, learn how to use code tags - the yellow background behind your code.
Edit - fseek is probably causing the problem. Your code works fine if you create a new text file
and comment it out.
Make sure to return a value from main.
Also, learn how to use code tags - the yellow background behind your code.
Edit - fseek is probably causing the problem. Your code works fine if you create a new text file
and comment it out.
Last edited by Colin Mac; May 3rd, 2008 at 9:41 am.
•
•
Join Date: Apr 2008
Posts: 294
Reputation:
Solved Threads: 11
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.55
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:990 0.0.0.0:0 LISTENING
TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1029 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1039 127.0.0.1:1040 ESTABLISHED
TCP 127.0.0.1:1040 127.0.0.1:1039 ESTABLISHED
TCP 127.0.0.1:1041 127.0.0.1:1042 ESTABLISHED
TCP 127.0.0.1:1042 127.0.0.1:1041 ESTABLISHED
TCP 127.0.0.1:5679 0.0.0.0:0 LISTENING
TCP 127.0.0.1:7438 0.0.0.0:0 LISTENING
TCP 192.168.0.45:139 0.0.0.0:0 LISTENING
UDP 0.0.0.0:445 *
UDP 0.0.0.0:500 *
UDP 0.0.0.0:1043 *
UDP 0.0.0.0:1229 *
UDP 0.0.0.0:1344 *
UDP 0.0.0.0:1816 *
UDP 0.0.0.0:4500 *
UDP 0.0.0.0:8000 *
UDP 127.0.0.1:123 *
UDP 127.0.0.1:1297 *
UDP 127.0.0.1:1900 *
UDP 192.168.0.45:123 *
UDP 192.168.0.45:137 *
UDP 192.168.0.45:138 *
UDP 192.168.0.45:1900 *
This is my xyz.txt
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.1.55
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:990 0.0.0.0:0 LISTENING
TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1029 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1039 127.0.0.1:1040 ESTABLISHED
TCP 127.0.0.1:1040 127.0.0.1:1039 ESTABLISHED
TCP 127.0.0.1:1041 127.0.0.1:1042 ESTABLISHED
TCP 127.0.0.1:1042 127.0.0.1:1041 ESTABLISHED
TCP 127.0.0.1:5679 0.0.0.0:0 LISTENING
TCP 127.0.0.1:7438 0.0.0.0:0 LISTENING
TCP 192.168.0.45:139 0.0.0.0:0 LISTENING
UDP 0.0.0.0:445 *
UDP 0.0.0.0:500 *
UDP 0.0.0.0:1043 *
UDP 0.0.0.0:1229 *
UDP 0.0.0.0:1344 *
UDP 0.0.0.0:1816 *
UDP 0.0.0.0:4500 *
UDP 0.0.0.0:8000 *
UDP 127.0.0.1:123 *
UDP 127.0.0.1:1297 *
UDP 127.0.0.1:1900 *
UDP 192.168.0.45:123 *
UDP 192.168.0.45:137 *
UDP 192.168.0.45:138 *
UDP 192.168.0.45:1900 *
This is my xyz.txt
![]() |
Similar Threads
- Front Page error when opening .HTM file (HTML and CSS)
- Dear everyone, nice to be here. and a problem regard GTK (C)
- Shell.dll file is reported as missing when quite clearly it's not. (Windows NT / 2000 / XP)
- Beginner problem compiling with javac (Java)
- Another hotoffers hijacking problem.. (Viruses, Spyware and other Nasties)
- Renaming files in C++ (C++)
- "Help" will not launch on Mac OS X 10.3.4 (OS X)
- cannot delete shortcut (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: Taking int like character
- Next Thread: Sorting a list of numbers
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






