Questions tagged [isspace]

Use the isspace tag for languages which provide a function or macro with that name to decide whether characters are white space, such as C or C++.

Some languages provide an isspace function or macro to enable programs to establish whether a specific character is white space or not.

Questions about this facility should use this tag.

26 questions
0
votes
1 answer

C++ Function does not seem to count the number of spaces in a text file

I'm trying to count different types of characters in a text file "nums.txt" I used a while loop with an ifstream object to check each character individually. Currently, all of my character types (punctuation, digits, uppercases, etc.) correctly…
Teaaaaaaa
  • 3
  • 1
0
votes
1 answer

Wrong output from code using isspace() test over index values

For some reason this code is not working correctly. I am trying to only replace dashes that do not have whitespace around them. However, dashes are still getting replaced when there is no white space. ls = [] for idx, letter in…
user9973598
0
votes
2 answers

I need to return number of words in c sting after taking user input

I need to make a program that takes input from the user and then return the number of words entered to the string. I store user input in array char words[256]; I have a function called countWords. It loops though the array and if it encounters a…
0
votes
0 answers

Determining if a file being inputted and read is really empty

I have written this void function to check input files being read are valid, but there is one thing I don't know how to implement. fseek and ftell are used to determine if a file is empty or not, but if a file is full of spaces or tabs, it will…
Scuba
  • 38
  • 6
0
votes
1 answer

cs50 initials pset2 unexpected error

I am getting an error (4, to be precise) when I try to use "i < n" in my for loop. If I take it out, I get an infinite loop. I also can't seem to get the if statement to run. Any thoughts on what I can improve? int main() { int i; int n; …
0
votes
2 answers

Extract a Word from a String

I'm working on a homework assignment, and I can't seem to get this function right. Does anyone have any ideas on why this won't work to create a substring consisting of the characters in between two spaces (word 0, word 1, etc...)? string…
0
votes
2 answers

Remove leading/trailing spaces without isspace()

I was looking for a standard way to remove leading spaces, and I found a pretty simple way using pointers and isspace(), however our professor won't allow us to use the library. Would the following work? char LeadingSpace(char *line) { …
Quinn Tai
  • 55
  • 1
  • 7
-1
votes
4 answers

Isspace function in python

I'm having trouble trying to execute this code, I want the user to input a value, the program checks if that value is a string then it returns the length. If the value contains whitespaces the programs remove the whitespace and print the…
Imran Abdalla
  • 115
  • 1
  • 10
-2
votes
1 answer

Calculate spaces in a string

I was trying to figure out how to calculate the number of spaces in a string when I came across this code online. Can someone please explain it? text = input("Enter Text: ") spaces = sum(c.isspace() for c in text) The issue im having is with the…
-2
votes
2 answers

Trying to count the number of words in a file

I have a file named myf which has a lot of text in it and I am trying to use blank spaces as a way of counting the number of words. Basically, in the count method of my program, there is a variable int d which acts like a boolean function. Also,…
Bossrevz
  • 33
  • 1
  • 4
1
2