• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 27 رای - 2.3 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: سورس کد خواندن فایل تکست (سی پلاس پلاس)
حالت موضوعی
#1
کد:
Read Text Filesvoid main()
{
char pcMyLines[10000]; ReadLines("C:\\MyTestFile.txt", 10, 5, pcMyLines, 12345);
}// This function reads n lines from a file
// Returns the amount of bytes read
int ReadLines(const char *pcFile, const int iStartLine, const int iTotLines, char *pcBuffer, const int iBufLen)
{
FILE *fSrc;
int   iLines = 0, j, iPos, iByteCount = 0; // Try to open the file
if(fSrc = fopen(pcFile, "r"))
{
   // Try to locate the starting line
   if(iPos = GetLinePos(fSrc, iStartLine))
   {
     // Set the starting position
     if(!fseek(fSrc, iPos, SEEK_SET))
     {
       // Read the lines
       for(iLines=0;iLines<iTotLines;iLines++)
       {
         // Read the line
         if((j = ReadLine(fSrc, iPos, pcBuffer, iBufLen - iByteCount)) == -1) break;
         iByteCount += j;
       }
     }
   }   // Close the file
   fclose(fSrc);
} // Return the amount of bytes in the buffer, or -1 for failure
return iLines == iTotLines ? iByteCount : -1;
}
// This function reads a single line from a file
int ReadLine(FILE *fSrc, const int iStartPos, char *pcBuffer, const int iBufLen)
{
int iCount = 0; // Set the starting position
if(!fseek(fSrc, iStartPos, SEEK_SET))
{
   // Keep reading characters while we can
   while(!feof(fSrc) && (iCount < iBufLen))
   {
     // Read the character
     pcBuffer[iCount] = (char)fgetc(fSrc);
     if(pcBuffer[iCount++] == '\n') break;
   }
}
else iCount = -1; return iCount;
}// This function locates a line in a file
// Returns the position of the line in the file
int GetLinePos(FILE *fSrc, const int iLine, const int iStartPos /* 0 */)
{
char  pcBuffer[4096];
int   i, iPos = 0, iLines = 0, iBytes; // Set the start position
if(!fseek(fSrc, iStartPos, SEEK_SET))
{
   // Read the (next) block of data
   while(iBytes = fread(pcBuffer, sizeof(char), 4096, fSrc))
   {
     // Go through the block
     for(i=0;i<iBytes;i++)
     {
       // Do we have a new line?
       if(pcBuffer[i] == '\n')
       {
         // Update the line count
         iLines++;         // Have we reached the desired line?
         if(iLines == iLine)
         {
           // Store the position
           iPos += i;
           break;
         }
       }
     }     // Update the position
     iPos += iBytes;
   }
} // Return the position of the line in the file, or -1 for failure
return iLines == iLine ? iPos : -1;
}
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
#2
سلام دوست عزیز این سورس شما می تونه یک فایل c++ رو بخونه و اگر خطایی داشت اون رو برگردونه من به همچین برنامه ای احتیاج دارم .. اگر راهنماییم کنید ممنون میشم.
 
پاسخ
#3
فکر کنم سورس دچار مشکلا تی هستش.
ایده شات
 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  گرافیک در سی پلاس پلاس jupiter2050 9 16,418 05-31-2014، 03:17 PM
آخرین ارسال: cnmeysam
  بهترین محیط (ide) برای برنامه نویسی c++ سی پلاس پلاس Amin_Mansouri 0 7,601 06-06-2013، 04:01 PM
آخرین ارسال: Amin_Mansouri
  سورس کد ایجاد افکت های مورد نظر (سی پلاس پلاس) Amin_Mansouri 0 3,561 12-06-2012، 12:29 PM
آخرین ارسال: Amin_Mansouri
  سورس کد دانلودر(سی پلاس پلاس) Amin_Mansouri 0 5,066 09-17-2012، 07:08 PM
آخرین ارسال: Amin_Mansouri
  سورس کد Thrip Port Scanner Amin_Mansouri 0 5,683 09-13-2012، 05:04 PM
آخرین ارسال: Amin_Mansouri
  سورس های ++C Ghoghnus 6 6,971 07-12-2012، 08:46 AM
آخرین ارسال: امیر
  سورس کد اینکریپت و دیکریپت (سی) Amin_Mansouri 1 3,493 07-07-2012، 05:13 PM
آخرین ارسال: one hacker alone
  سورس کد نمایش حجم فایل مورد نظر (سی) Amin_Mansouri 0 2,844 06-16-2012، 08:32 PM
آخرین ارسال: Amin_Mansouri
  سورس کد تبدیل مگابایت به کیلوبایت (سی) Amin_Mansouri 0 4,527 06-16-2012، 08:28 PM
آخرین ارسال: Amin_Mansouri
  سورس کد خالی کردن سطل زباله سیستم عامل ( سی ) Amin_Mansouri 0 2,758 06-16-2012، 08:25 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 2 مهمان