Re: [Dev-C++] <Dec-C++>Please give me your feedbacks!
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-11-05 10:18:08
|
1) If you have problems with school assignments, why don't you just admit
that? An embedded system - where there might not be an existing RTL,
forcing the developer to write it's own strtoi doesn't need wide character
support...
2) Why do a loop that both uses an index and counts size? Why isn't the
size variable enough to locate the last character. Why isn't this loop
breaking at the first non-digit?
3) Real strtoi doesn't write any error messages. There might not even be a
console for emitting any messages... It should just stop at the
first invalid character.
4) Why do nested loops for exponent? A real implementation converts from
end of string, just multiplying the previous sum by 10 every time it has
one more digit to process.
5) You have missed handling numbers starting with a sign. 6) How do you
think you can load a text string with scanf without allocating the memory.
You have a pointer but that doesn't point to a text buffer for storing
your digit string.
/Per W
On Fri, 5 Nov 2004, Justin Fan wrote:
> Hi,
>
> I'm newer to C++ programming so I hope you can help me to improve my
> coding skill. Here is my first code to implement Strtoi(char*), please
> give me your feedback.
> My lead ask me to implement it as Strtoi(wchar*), but I can't find
> which head contains the definition of wchar and how to use it. And
> some known bugs are there after tesing:
>
> when I input a long string such as "12345678987654321", this app will crash.
> Also when I add a sentence before sleep(), it crashed.
>
> BTW, I want to know how to debug an app and how to track views I added.
>
> Any ideas?
>
> Thanks in advance and any suggestions will be appreciated!!
>
> #include <stdlib.h>
>
> int strtoi(char* a)
> {
>
> int sum=0,size=0,i=0;
>
> while(a[i]!='\0') // calculate the size of the array
> {i++;size++;}
>
> printf("The size of string is: %d\n",size);
> i=0;
>
>
> for(i=0;i<size;i++)
> {
> if (a[i]<'0' || a[i]>'9') //Don't deal with invalid strings
> { printf( "I think it's meaningless to covert a English word to
> int.\n Please input some string such as 123");
> return 0;
> }
> else
> {
> int j=0; //variable 'j' refers to the exponet of 10
> int temp=a[i]-'0'; //covert a[i] to a interger
> for(j=size-i-1;j>0;j--) //sum
> temp=temp*10;
>
> sum+=temp;
> }
> }
> printf("The result of convertion:%d\n",sum);
> return sum;
>
> }
> int main()
> {
> int i=0;
> char* a;
> printf("Please input your string,such as 123\n");
> scanf("%s",a);
> strtoi(a);
> sleep(100000);
> return 0;
> }
>
> --
> Thanks
> Z.J.
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|