getw()

This is a discussion on getw() within the C Programming forums, part of the General Programming Boards category; why does the getw in this program always return -1?? Code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { FILE *f1; char ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    384

    getw()

    why does the getw in this program always return -1??

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h> 
    
    int main()
    {
    	FILE *f1;
    	char c;
    	int i,n;
    
    	f1=fopen("data1","w");
    	if(f1==NULL)
    	{
    		printf("Could not open file");
    		exit(0);
    	}
    	
    	scanf("%d",&i);
    	while(i!=-1)
    	{
    		putw(i,f1);
    		scanf("%d",&i);
    	}
    
    	fseek(f1,0,0);
    	i=getw(f1);
    	printf("%d",i);
    
            fclose(f1);
    }

  2. #2
    Registered User
    Join Date
    Aug 2011
    Posts
    384
    got it... sorry...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getw/putw problem
    By fenikkusu in forum C Programming
    Replies: 6
    Last Post: 02-20-2009, 12:21 AM
  2. Reading files number by number, also getw()?
    By rmullen3 in forum C Programming
    Replies: 4
    Last Post: 01-03-2003, 12:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21