C
coinjo
Is there any function to determine the length of an integer string?
coinjo said:Is there any function to determine the length of an integer string?
coinjo said:Is there any function to determine the length of an integer string?
coinjo said:#include<iostream>
#include<fstream>
using namespace std;
void selectionSort(int list[], int length)
{
int main()
{
int s[100];
int c=0;
int count=0;
ifstream a;
a.open("in.txt");
selectionSort(s,10);
while(a>>s[count] && !a.eof())
{
count++;
}
c=strlen(s);
whether i include cstring file or not i get an error message in vc++;
(40) : error C2664: 'strlen' : cannot convert parameter 1 from 'int
[100]' to 'const char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
coinjo said:#include<iostream>
#include<fstream>
using namespace std;
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
void selectionSort(int list[], int length)
{
int index;
int smallestIndex;
int minIndex;
int temp;
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.7
for(index=0; index<length-1; index++)
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.15
{
smallestIndex=index;
for(minIndex=index+1; minIndex<length; minIndex++)
if(list[minIndex]<list[smallestIndex])
smallestIndex=minIndex;
temp=list[smallestIndex];
list[smallestIndex]=list[index];
list[index]=temp;
}
};
int main()
{
int s[100];
int c=0;
int count=0;
ifstream a;
a.open("in.txt");
selectionSort(s,10);
while(a>>s[count] && !a.eof())
{
count++;
}
c=strlen(s);
return 0;
}
in.txt contains:
9
8
7
6
5
4
3
2
1
whether i include cstring file or not i get an error message in vc++;
(40) : error C2664: 'strlen' : cannot convert parameter 1 from 'int
[100]' to 'const char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
#include<iostream.h>
#include<fstream>
#include<cstring>
#include<math.h>
Prefer said:using namespace std;
void selectionSort(int list[], int length)
{
int index;
int smallestIndex;
int minIndex;
int temp;
for(index=0; index<length-1; index++)
{
smallestIndex=index;
for(minIndex=index+1; minIndex<length; minIndex++)
if(list[minIndex]<list[smallestIndex])
smallestIndex=minIndex;
temp=list[smallestIndex];
list[smallestIndex]=list[index];
list[index]=temp;
}
};
void main()
{
int s[100];
int c=0;
int count=0;
ifstream a;
a.open("in.txt");
int total_digits = 0;
while(a>>s[count] && !a.eof())
{
total_digits += log10(s[count]) + 1;
count++;
}
count=0;
selectionSort(s,total_digits);
while(count<total_digits)
{
cout<<s[count]<<endl;
count++;
}
}
Thanks to all of you for your generous help, I now have come up with
this and as far as i thinks, it works! Please post any suggestions or
corrections (if there are any) to this.
Jonathan said:Prefer <cmath>
Thanks to all of you for your generous help, I now have come up with
this and as far as i thinks, it works! Please post any suggestions or
corrections (if there are any) to this.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.