String probs in C

Status
Not open for further replies.

bugbum1

Ars Scholae Palatinae
893
foo = sizeof(buffer)-1;

token = fgets(buffer,sizeof(buffer)-1,instream);


while (fgets(buffer,sizeof(buffer)-1,instream) != NULL)
{
printf("%s", buffer);
linenum++;

/*
token = strtok(buffer," "); // Get first token from string buffer

while (token != NULL)
{
{
tnum = 0;
// Search for current token in tokens
while ((tnum < ntokens) && (strcmp(token,tokens[tnum])))
tnum++;

// If the token isn't found, add it to the tokens
if (tnum == ntokens) {

tokens[tnum] =(char *) calloc(strlen(token) + 1,sizeof(char));
strcpy(tokens[tnum],token);
tokenline[tnum] = linenum;
ntokens++;
}
}
// Get next token from string buffer
token = strtok(NULL, " ");
printf("Token as a string is: %s\n", token);



}

*/
// print out the set of tokens appearing in the file
for (tnum = 0; tnum < ntokens; tnum++)
printf("%s first appears on line %d\n",tokens[tnum],tokenline[tnum]);
// fclose(instream);
}
return 0;
}
 
------------------------
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int parse();
int main()
{    parse();
}


int parse()
{

    //Declarations
    FILE *instream;
    char buffer[101];
    char *token;
    char *tokens[100];
    int tokenline[100];
    int ntokens=0;
    int linenum=0;
    int tnum;
    int controller;
    //Statements
    if ((instream = fopen("prg8.dat","r")) == NULL) {
        printf("Unable to open the file");
        }
    else 
        printf("File opened successfully\n");

while (fgets(buffer,sizeof(buffer)-1,instream) != NULL) 
{printf("%s", buffer);
        linenum++;
    // Get first token from string buffer 
    token = strtok(buffer," ");
        
        while (token != NULL) 
        {    {
        tnum = 0;
        // Search for current token in tokens
            while ((tnum < ntokens) && (strcmp(token,tokens[tnum])))
            tnum++;
        
    // If the token isn

[This message was edited by Locke on November 27, 2001 at 11:00.]
 
Alright, i was cruisin' along good, fixin' the probs, speadin' the love, in my programand once again I ran into a problem.
I am trying to print this but with "****" instead of any 4 letter words. instead i get this

code:<HR>
Code:
File opened successfully
Characters are the fundamental building blocks of source programs.
 Every program is composed of a sequence of characters **** - when grouped
 Every  together meaningfully - is interpreted by the compiler as a series of
 Every  instructions used to accomplish a task .
 Every
 Every  A string is a series of characters treated as a single **** . In C a
Ideas? Suggestions? Where to find a proffesor that can write a shell program that works?
 
Status
Not open for further replies.