#include <iostream>
#include <fstream>
#define size 1000
using namespace std;
void main ()
{
int s=size;
int NoDupArray[size];
int idx,value,i=0;
int Num;
fstream f("test.txt",ios::in);
if(!f)
{
cout<<"Can't Find This File"<<endl;
exit(1);
}
while (f>>NoDupArray)
{
i++;
}
for (idx = 0; idx < size; idx++)
{
for(value=size;value>idx;value--)
if (NoDupArray[idx]==NoDupArray[value])
{
NoDupArray[value]=NoDupArray[value+1];
s=s-1;
}
}
for(int i=0;i<size;i++)
{
cout<<NoDupArray<<endl;
}
}[ تمت الإجابة ]استخراج الأعداد الغير مُكررة من ملف نص¡
الكود صحيح (من ناحية الــ Syntax) فقط تنقصه إضافة المكتبة cstdlib لكي تستطيع استخدام الدالة exit.
C++ and Java, say, are presumably growing faster than plain C, but I bet C will still be around. ― Dennis Ritchie
~OoO~________--------------------------------------------________~OoO~
من مواضيعي :
ايوة ما انا عارف انه صح من ناحية ال syntex لكن الكود نفسه غلط لوجيك
يعنى انا عايز اخد شوية قيم من ملف وبعدين اخزنهم في اراي من غير تكرار لو كان فيهم ارقام مكررة
uuuuuuuuuup
أوكي, إليك تصحيح الكود:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc, char** argv) {
int fileToArray[100];
int index, value, i = 0;
bool exist;
fstream file("data.txt", ios::in);
if (!file) {
cout << "Can't Find This File" << endl;
exit(1);
}
while (file >> value) {
exist = false;
for (index = 0; index < i; index++)
if (fileToArray[index] == value) {
exist = true;
break;
}
if (exist == false)
fileToArray[i++] = value;
}
for (int j = 0; j < i; j++) {
cout << fileToArray[j] << endl;
}
return 0;
}في المرات القادمة, قم بطرح سؤالك بصفة أكثر دقة لأن الكود وحده لا يكفي.
تحياتي.
C++ and Java, say, are presumably growing faster than plain C, but I bet C will still be around. ― Dennis Ritchie
~OoO~________--------------------------------------------________~OoO~
من مواضيعي :
تم تعديل العنوان ليُناسب مُحتوى الموضوع أكثر.
C++ and Java, say, are presumably growing faster than plain C, but I bet C will still be around. ― Dennis Ritchie
~OoO~________--------------------------------------------________~OoO~
من مواضيعي :
تمام وشكرا جزيلا لحضرتك :)