ÍÁÎÊ linux C ±à³Ì rename º¯Êý
linux ²ËÄñÇó rename º¯ÊýµÄ ¾ßÌåÓ÷¨
ÔÚÎҵijÌÐòÖÐÎÒµÄÉèÏëÊÇ £ºÔÚÒ»¸öÖÆ¶¨ÐÂĿ¼AÏÂÐÂopen Ò»¸ö newfile-¡µÓÃfwn µÄfn ±éÀúÔĿ¼ÏÂBµÄËùÓÐÎļþ-¡µ Èç¹ûÊÇÎļþÔò°Ñÿ¸öÎļþ·Ö±ðͨ¹ýnewfile copy µ½ newfile£¬²¢ÇÒrename ³ÉËûÔÀ´µÄÃû×Ö£¬Èç¹ûÊǸöĿ¼ÔòÖØ¸´µÚ¶þ²½£¬Ö±µ½ÔÀ´µÄĿ¼BÏÂËùÓÐÎļþ¶¼±»±éÀú¹ý¡£
µ±rename ²úÉú³åͻʱ£¬¼´ ÓÐ2 ¸öB Ŀ¼ÏµÄÔÎļþÓÐÏàͬµÄÃû×Ö£¬ÔòÔÚÃüÃûʱºò¼ÓÉÏ1£¬2£¬3¡£¡£¡£¡£×÷ÎªÇø±ð
Èç
1£¬ÔÚB Ŀ¼Ï¿½±´ÁËÒ»¸ö½Ð main.c µÄµ½A
2£¬±éÀú B Ŀ¼ÏµÄĿ¼ C ÓÖ·¢ÏÖÒ»¸ö½Ðmain.c µÄ£¬Ôò¿½±´µ½AʱºòÃüÃûΪ main.c.1
RENAME(2) Linux Programmer¡¯s Manual RENAME(2)
NAME
rename - change the name or location of a file
SYNOPSIS
#include <stdio.h>
int rename(const char *oldpath, const char *newpath);
DESCRIPTION
rename renames a file, moving it between directories if required.
Any other hard links to the file (as created using link(2)) are unaffected.
If newpath already exists it will be atomically replaced (subject to a few conditions - see ERRORS below), so
that there is no point at which another process attempting to access newpath will find it missing
Ïà¹ØÎÊ´ð£º
ÎÊһϣº
#include <stdio.h>
int main()
{
char x, y, z;
int i;
int a[16];
for(i=0; i<=16; i++)
{
a[i] = 0;
......
ÎÊÌâ:¹¤µØÉÏÐèÒª³¤¶ÈΪA1µÄ¸Ö½îX¸ù,³¤¶ÈΪA2µÄ¸Ö½îY¸ù,³¤¶ÈΪA3µÄ¸Ö½îZ¸ù......ÒÔ´ÎÀàÍÆ.
ÆäÖÐA1,A2,A3,...³¤¶ÈÈÎÒâÖ¸¶¨,X,Y,Z,...ÊýÁ¿Ò²ÈÎÒâÖ¸¶¨.
µ«²Ö¿âÖеĸֽîΪ±ê×¼³¤¶È,Ö»ÓÐ9Ã׺Í15Ã×Á½ÖÖ³¤¶È,ÊýÁ¿² ......
ÓÃc/c++¶¨Î»É¾³ýÒ»ÐеÄÎÊÌâ¡£
ÎÊÌâ±³¾°£º
ËùÐèÊý¾ÝÏ൱´ó¡£aÓëbÎļþ¾ùΪһ×éÎļþ£¨a1£¬a2¡£¬b1£¬b2¡£©£¬aÎļþÓÐ×î´óÊý¾ÝÐÐÊý£¨Èç5000£©£¬ÒÔÐеÄÐÎʽ£¬´ÓaÎļþÖжÁÈ¡Êý¾Ý£¬½«aÖв»ÄÜ´¦ÀíµÄÊý¾Ý·ÅÔÚbÎ ......
дÁ˸ö²âÊÔ³ÌÐòÈçÏÂ
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......