Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > can someone help me how to compile this program??

Reply
Thread Tools

can someone help me how to compile this program??

 
 
Anarki
Guest
Posts: n/a
 
      10-01-2008
The following is the program i am trying to compile

//restrict.c
#include <stdio.h>
int main()
{
char arr[10] = "Qualifiers"
char * restrict p = arr;
int i = 0;
for(; i < 10; ++i)
printf("%c", arr[i]);
return 0;
}

i am using cygwin in window xp SP2, my gcc version is 3.4.4

how do i compile the above program?

i tried using this

gcc -c -std=c99 restrict.c

but i get an error like this

restrict.c: In function 'main':
restrict.c:6: error: parse error before "char"

can someone help me how to compile this program??
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-01-2008
Anarki wrote:
> The following is the program i am trying to compile
>
> //restrict.c
> #include <stdio.h>
> int main()
> {
> char arr[10] = "Qualifiers"


Missing semicolon.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
MisterE
Guest
Posts: n/a
 
      10-01-2008
> char arr[10] = "Qualifiers"

you are missing ;
try:
char arr[10] = "Qualifiers";


 
Reply With Quote
 
Anarki
Guest
Posts: n/a
 
      10-01-2008
On Oct 1, 1:31*pm, MisterE <(E-Mail Removed)> wrote:
> > * *char arr[10] = "Qualifiers"

>
> you are missing ;
> try:
> char arr[10] = "Qualifiers";


omg! i didnt see tht *** semicolon srry thread closed!
 
Reply With Quote
 
Anarki
Guest
Posts: n/a
 
      10-01-2008
On Oct 1, 1:31*pm, Ian Collins <(E-Mail Removed)> wrote:
> Anarki wrote:
> > The following is the program i am trying to compile

>
> > //restrict.c
> > #include <stdio.h>
> > int main()
> > {
> > * *char arr[10] = "Qualifiers"

>
> Missing semicolon.
>
> --
> Ian Collins.


Thx to Ian Collins and MisterE
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      10-01-2008
Anarki wrote:
> The following is the program i am trying to compile
>
> //restrict.c
> #include <stdio.h>
> int main()


Better: int main(void)

> {
> char arr[10] = "Qualifiers"


Others told you about the missig ; here, but as yet nobody mentioned that
arr[10] is too short to hold the string "Qualifiers". You need arr[11] to
have enough space for the terminating '\0'.
You could automate that by using arr[] = "Qualifiers"; but then may have to
adjust your for loop.

> char * restrict p = arr;
> int i = 0;
> for(; i < 10; ++i)
> printf("%c", arr[i]);
> return 0;
> }
>
> i am using cygwin in window xp SP2, my gcc version is 3.4.4
>
> how do i compile the above program?
>
> i tried using this
>
> gcc -c -std=c99 restrict.c
>
> but i get an error like this
>
> restrict.c: In function 'main':
> restrict.c:6: error: parse error before "char"
>
> can someone help me how to compile this program??


Bye, Jojo


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-01-2008
Joachim Schmitz wrote:
> Anarki wrote:
>> The following is the program i am trying to compile
>>
>> //restrict.c
>> #include <stdio.h>
>> int main()

>
> Better: int main(void)
>
>> {
>> char arr[10] = "Qualifiers"

>
> Others told you about the missig ; here, but as yet nobody mentioned that
> arr[10] is too short to hold the string "Qualifiers". You need arr[11] to
> have enough space for the terminating '\0'.


It's legal to use a string literal to initialize an array that is not
big enough to hold the terminating '\0' (6.7.8p14). He does not use arr
in any way that requires it, so why should he provide space to store it?

> You could automate that by using arr[] = "Qualifiers"; but then may have to
> adjust your for loop.
>
>> char * restrict p = arr;
>> int i = 0;
>> for(; i < 10; ++i)
>> printf("%c", arr[i]);
>> return 0;
>> }

 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      10-01-2008
James Kuyper wrote:
> Joachim Schmitz wrote:
>> Anarki wrote:

<snip>
>>> char arr[10] = "Qualifiers"

>>
>> Others told you about the missig ; here, but as yet nobody mentioned
>> that arr[10] is too short to hold the string "Qualifiers". You need
>> arr[11] to have enough space for the terminating '\0'.

>
> It's legal to use a string literal to initialize an array that is not
> big enough to hold the terminating '\0' (6.7.8p14). He does not use
> arr in any way that requires it, so why should he provide space to
> store it?


It may be legal to do so and he might not use it in this program, but it is
a common enough mistake to forget to allocate space for the terminating '\0'
to make it worthwhile being mentioned, wouldn't you agree?

Bye, Jojo


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-01-2008
Joachim Schmitz wrote:
> James Kuyper wrote:
>> Joachim Schmitz wrote:
>>> Anarki wrote:

> <snip>
>>>> char arr[10] = "Qualifiers"
>>> Others told you about the missig ; here, but as yet nobody mentioned
>>> that arr[10] is too short to hold the string "Qualifiers". You need
>>> arr[11] to have enough space for the terminating '\0'.

>> It's legal to use a string literal to initialize an array that is not
>> big enough to hold the terminating '\0' (6.7.8p14). He does not use
>> arr in any way that requires it, so why should he provide space to
>> store it?

>
> It may be legal to do so and he might not use it in this program, but it is
> a common enough mistake to forget to allocate space for the terminating '\0'
> to make it worthwhile being mentioned, wouldn't you agree?


Perhaps, but the mention should have been written in a way that
acknowledges the possibility that the knew precisely what he was doing.
The way you wrote it left the impression that his code was unambiguously
wrong. You said "too short" and "you need", when it was precisely big
enough for everything he was going to do with it, and he therefore did
not need to make the change that you suggested.
 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      10-01-2008
James Kuyper wrote:
> Joachim Schmitz wrote:
>> James Kuyper wrote:
>>> Joachim Schmitz wrote:
>>>> Anarki wrote:

>> <snip>
>>>>> char arr[10] = "Qualifiers"
>>>> Others told you about the missig ; here, but as yet nobody
>>>> mentioned that arr[10] is too short to hold the string
>>>> "Qualifiers". You need arr[11] to have enough space for the
>>>> terminating '\0'.
>>> It's legal to use a string literal to initialize an array that is
>>> not big enough to hold the terminating '\0' (6.7.8p14). He does not
>>> use arr in any way that requires it, so why should he provide space
>>> to store it?

>>
>> It may be legal to do so and he might not use it in this program,
>> but it is a common enough mistake to forget to allocate space for
>> the terminating '\0' to make it worthwhile being mentioned, wouldn't
>> you agree?

>
> Perhaps, but the mention should have been written in a way that
> acknowledges the possibility that the knew precisely what he was
> doing. The way you wrote it left the impression that his code was
> unambiguously wrong. You said "too short" and "you need", when it was
> precisely big enough for everything he was going to do with it, and
> he therefore did not need to make the change that you suggested.


OK, point taken.

Bye, Jojo


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Can someone compile WinVN with Digital Mars IDDE? Janne Naukkarinen C++ 0 01-14-2004 07:51 PM
Could someone successfully compile perl 5.8.1 with mingw 3.1.0-1? Albert Albani Perl Misc 1 11-03-2003 05:32 PM
someone wants to compile wxRuby for Andy Hunt's Windows Installer for me? Gerard A.W. Vreeswijk Ruby 0 08-19-2003 07:46 PM



Advertisments